<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Moment.js Documentation - Moment.js Documentation | Docs4dev</title>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="Parse, validate, manipulate, and display dates and times in JavaScript.">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="true">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta property="og:type" content="website">
<meta property="og:title" content="Moment.js Documentation - Moment.js Documentation">
<meta property="og:url" content="https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/">
<meta property="og:site_name" content="Docs4dev">
<meta property="og:locale" content="zh_CN">
<meta name="twitter:card" content="Parse, validate, manipulate, and display dates and times in JavaScript.">
<meta name="generator" content="Docs4dev template engine">
<link rel="stylesheet" href="static/css/app.min.css">
<link rel="shortcut icon" href="https://www.docs4dev.com/static/images/favicon.ico" type="image/x-icon">
<script async="" src="static/js/js.js"></script>
<script async="" src="static/js/adsbygoogle.js" crossorigin="anonymous"></script>
<script>
    window.dataLayer = window.dataLayer || [];

    function gtag() {
      dataLayer.push(arguments);
    }

    gtag('js', new Date());
    gtag('config', 'UA-129571937-1');
  </script>
<link rel="amphtml" href="https://www.docs4dev.com/amp/docs/en/momentjs/2.24.0/documentation/index.html">

<script type="application/ld+json">{"name":null,"headline":"Moment.js Documentation-Moment.js Documentation","inLanguage":"en-US","version":"2.24.0","image":"/static/icon/icon-momentjs.png","datePublished":"2021-05-20T12:51:01Z","dateCreated":"2021-05-20T12:51:01Z","dateModified":"2021-07-03T12:24:36Z","@context":"https://schema.org/","@type":"APIReference","abstract":"Parse, validate, manipulate, and display dates and times in JavaScript."}</script>
</head>
<body>
<div class="book with-summary">
<div class="book-summary">
<div class="logo">
<a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation');" style="color: inherit;">
<img src="static/picture/icon-momentjs.png" style="width: 48px; height: 48px;" alt="Logo">
</a>
<b style="color: inherit; margin-left: 8px;">Moment.js Documentation</b>
</div>
<div class="item">
<div>
<label for="version">版本</label>
<select id="version" onchange="onVersionChange(this)">
<option value="2.24.0" selected="selected">2.24.0</option>
</select>
</div>
<div style="margin-top: 8px;">
<label for="language">语言</label>
<select id="language" onchange="onLangChange(this)" value="en">
<option value="en" selected="selected">English</option>
<option value="zh">中文</option>
</select>
</div>

</div>
<div class="item menus">
<a title="Table of Contents" style="margin-right: 8px;" href="#">
<i class="fa fa-chevron-left"></i>
 <span style="margin-left: 2px;">返回目录</span>
</a>
</div>
<nav role="navigation" id="navigation">
<ul class="summary">
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/');" title="Where to use it"> Where to use it </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/node-js/');" title="Node.js"> Node.js </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/browser/');" title="Browser"> Browser </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/bower/');" title="Bower"> Bower </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/require-js/');" title="Require.js"> Require.js </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/nuget/');" title="NuGet"> NuGet </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/meteor/');" title="meteor"> meteor </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/browserify/');" title="Browserify"> Browserify </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/webpack/');" title="Webpack"> Webpack </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/typescript/');" title="Typescript"> Typescript </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/system-js/');" title="System.js"> System.js </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/other/');" title="Other"> Other </a> </li>
<li class="chapter"> <a href="javascript:window.open('https://www.docs4dev.com/docs/en/momentjs/2.24.0/documentation/index.html#/use-it/troubleshooting/');" title="Troubleshooting"> Troubleshooting </a> </li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<header class="book-header">
<div class="dropdown pull-right js-toolbar-action">
<a class="btn toggle-dropdown" aria-label="Language" href="#">
<i class="fa fa-globe"></i>
</a>
<div class="dropdown-menu dropdown-left">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<button class="button size-1" onclick="changeLang('zh_CN')">中文</button>
</div>
<div class="buttons">
<button class="button size-1" onclick="changeLang('en_US')">English</button>
</div>
</div>
</div>
<a class="btn pull-right js-toolbar-action non-mobile" aria-label="Sign up" href="register.html">
<i class="fa fa-sign-in"></i> <span>注册</span>
</a>
<a class="btn pull-right js-toolbar-action non-mobile" aria-label="Sign in" href="register.html">
<i class="fa fa-sign-in"></i>
<span>登录</span>
</a>
<a class="btn pull-left js-toolbar-action btn-summary" href="#"><i class="fa fa-align-justify"></i></a>
<div class="dropdown pull-left font-settings js-toolbar-action">
<a class="btn toggle-dropdown" aria-label="Font Settings" href="#">
<i class="fa fa-font"></i>
</a>
<div class="dropdown-menu dropdown-right">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<button class="button size-2 font-reduce">A</button>
<button class="button size-2 font-enlarge">A</button>
</div>
<div class="buttons">
<button class="button size-2 family-serif">Serif</button>
<button class="button size-2 family-sans">Sans</button>
</div>
<div class="buttons">
<button class="button size-3 theme-white">White</button>
<button class="button size-3 theme-sepia">Sepia</button>
<button class="button size-3 theme-night">Night</button>
</div>
</div>
</div>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Home" href="en.html">
<i class="fa fa-home"></i> <span>首页</span>
</a>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Guide" href="javascript:window.open('https://www.javadoc.org/');">
<i class="fa fa-book"></i> <span>API Docs</span>
</a>
<a class="btn pull-left js-toolbar-action non-mobile" aria-label="Tools" href="index37.html">
<i class="fa fa-gears"></i> <span>工具</span>
</a>
<div class="dropdown pull-left js-toolbar-action mobile">
<a class="btn toggle-dropdown" aria-label="Language" href="#">
<i class="fa fa-chevron-down"></i>
</a>
<div class="dropdown-menu dropdown-right">
<div class="dropdown-caret"><span class="caret-outer"></span><span class="caret-inner"></span></div>
<div class="buttons">
<a class="button size-1" aria-label="Home" href="en.html">
<i class="fa fa-home"></i> <span>首页</span>
</a>
</div>
<div class="buttons">
<a class="button size-1" aria-label="Guide" href="javascript:window.open('https://www.javadoc.org/');">
<i class="fa fa-book"></i> <span>API Docs</span>
</a>
</div>
<div class="buttons">
<a class="button size-1" aria-label="Tools" href="index37.html">
<i class="fa fa-gears"></i> <span>工具</span>
</a>
</div>
</div>
</div>
<div id="autocomplete" class="pull-right"></div>
<span id="toolbar-title"></span>
</header>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal markdown-section">
<div id="content">
<h1>Moment.js Documentation</h1>
<div><ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6108808167664152" data-ad-slot="6964403648"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
<div><article class="docs-section">
<a class="docs-section-target" id="/use-it/" name="/use-it/"></a>
<h2 class="docs-section-title" id="Where-to-use-it"><a href="#/use-it/">Where to use it</a></h2>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/intro/" name="/use-it/intro/"></a>
<div class="docs-method-prose">
<p>Moment was designed to work both in the browser and in Node.js.</p>
<p>All code should work in both of these environments, and all unit tests are run in both of these environments.</p>
<p>Currently, the following browsers are used for the ci system: Chrome on Windows XP, IE 8, 9, and 10 on Windows 7, IE 11 on Windows 10, latest Firefox on Linux, and latest Safari on OSX 10.8 and 10.11.</p>
<p>If you want to try the sample codes below, just open your browser's console and enter them.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/node-js/" name="/use-it/node-js/"></a>
<h3 class="docs-method-title" id="Node.js"> <a href="#/use-it/node-js/">Node.js</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/01-node-js.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<pre class="notranslate"><code>npm install moment
</code></pre>
<pre class="notranslate"><code class="language-javascript">var moment = require('moment'); // require
moment().format(); 
</code></pre>
<p>Or in ES6 syntax:</p>

<pre class="notranslate"><code class="language-javascript">import moment from 'moment';
moment().format();
</code></pre>
<p><strong>Note:</strong> if you want to work with a particular variation of moment timezone, for example using only data from 2012-2022, you will need to import it from the <code class="notranslate">builds</code> directory like so:</p>

<pre class="notranslate"><code class="language-javascript">import moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022';
</code></pre>
<p><strong>Note:</strong> In <strong>2.4.0</strong>, the globally exported moment object was <strong>deprecated</strong>. It will be removed in next major release.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/browser/" name="/use-it/browser/"></a>
<h3 class="docs-method-title" id="Browser"> <a href="#/use-it/browser/">Browser</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/02-browser.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<pre class="notranslate"><code>&lt;script src="moment.js"&gt;&lt;/script&gt;
&lt;script&gt;
    moment().format();
&lt;/script&gt;
</code></pre>
<p>Moment.js is available on <a href="javascript:window.open('https://cdnjs.com/libraries/moment.js');" target="_blank" rel="noopener noreferrer">cdnjs.com <i class="fa fa-external-link"></i></a> and on <a href="javascript:window.open('https://www.jsdelivr.com/package/npm/moment');" target="_blank" rel="noopener noreferrer">jsDelivr <i class="fa fa-external-link"></i></a>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/bower/" name="/use-it/bower/"></a>
<h3 class="docs-method-title" id="Bower"> <a href="#/use-it/bower/">Bower</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/03-bower.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<p><a href="javascript:window.open('https://bower.io/');" target="_blank" rel="noopener noreferrer">bower <i class="fa fa-external-link"></i></a></p>
<pre class="notranslate"><code>bower install --save moment
</code></pre>
<p>Notable files are <code class="notranslate">moment.js</code>, <code class="notranslate">locale/*.js</code> and <code class="notranslate">min/moment-with-locales.js</code>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/require-js/" name="/use-it/require-js/"></a>
<h3 class="docs-method-title" id="Require.js"> <a href="#/use-it/require-js/">Require.js</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/04-require-js.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<p>We strongly recommend reading <a href="javascript:window.open('https://github.com/requirejs/requirejs/issues/1554#issuecomment-226269905');" target="_blank" rel="noopener noreferrer">this <i class="fa fa-external-link"></i></a> if you plan to use moment with Require.js. Also upgrade to <strong>2.14.0</strong> or above for best experience.</p>
<p>As a start, you might have acquired moment through bower or node_modules or anything else that places moment.js together with a locales directory in a base folder. Then you should use a tool like <a href="javascript:window.open('https://github.com/jrburke/adapt-pkg-main');" target="_blank" rel="noopener noreferrer">adapt-pkg-main <i class="fa fa-external-link"></i></a>, or manually -- using <a href="javascript:window.open('http://requirejs.org/docs/api.html#packages');" target="_blank" rel="noopener noreferrer">packages config <i class="fa fa-external-link"></i></a>.</p>

<pre class="notranslate"><code class="language-javascript">requirejs.config({
  packages: [{
    name: 'moment',
    // This location is relative to baseUrl. Choose bower_components
    // or node_modules, depending on how moment was installed.
    location: '[bower_components|node_modules]/moment',
    main: 'moment'
  }]
});
</code></pre>
<p>With the above setup, you can require the core with <code class="notranslate">moment</code> and <code class="notranslate">de</code> locale with <code class="notranslate">moment/locale/de</code>.</p>

<pre class="notranslate"><code class="language-javascript">// only needing core
define(['moment'], function (moment) {
    console.log(moment().format('LLLL'));  // 'Friday, June 24, 2016 1:42 AM'
});

// core with single locale
define(['moment', 'moment/locale/de'], function (moment) {
    moment.locale('de');
    console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});

// core with all locales
define(['moment/min/moment-with-locales'], function (moment) {
    moment.locale('de');
    console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
});

// async load locale
define(['require', 'moment'], function(require, moment) {
  // Inside some module after the locale is detected. This is the
  // case where the locale is not known before module load time.
  require(['moment/locale/de'], function(localeModule) {
    // here the locale is loaded, but not yet in use
    console.log(moment().format('LLLL'));  // 'Friday, June 24, 2016 1:42 AM'

    moment.locale('de');
    // Use moment now that the locale has been properly set.
    console.log(moment().format('LLLL')); // 'Freitag, 24. Juni 2016 01:42'
  })
});
</code></pre>
<p>For more complicated use cases please read <a href="javascript:window.open('https://github.com/requirejs/requirejs/issues/1554#issuecomment-226269905');" target="_blank" rel="noopener noreferrer">excellent explanation by @jrburke <i class="fa fa-external-link"></i></a>.</p>
<p>Moment will still create a <code class="notranslate">moment</code> global, which is useful to plugins and other third-party code. If you wish to squash that global, use the <code class="notranslate">noGlobal</code> option on the module config.</p>

<pre class="notranslate"><code class="language-javascript">require.config({
    config: {
        moment: {
            noGlobal: true
        }
    }
});
</code></pre>
<p>If you don't specify <code class="notranslate">noGlobal</code> then the globally exported moment will print a deprecation warning. From next major release you'll have to export it yourself if you want that behavior.</p>
<p>For version <strong>2.5.x</strong>, in case you use other plugins that rely on Moment but are not AMD-compatible you may need to add <a href="javascript:window.open('https://github.com/jrburke/r.js/blob/b8a6982d2923ae8389355edaa50d2b7f8065a01a/build/example.build.js#L68-L78');" target="_blank" rel="noopener noreferrer"><code class="notranslate">wrapShim: true</code> <i class="fa fa-external-link"></i></a> to your r.js config.</p>
<p><strong>Note:</strong> To allow moment.js plugins to be loaded in requirejs environments, moment is created as a named module. Because of this, moment <strong>must</strong> be loaded exactly as as <code class="notranslate">"moment"</code>, using <code class="notranslate">paths</code> to determine the directory. Requiring moment with a path like <code class="notranslate">"vendor\moment"</code> will return <code class="notranslate">undefined</code>.</p>
<p><strong>Note:</strong> From version <strong>2.9.0</strong> moment exports itself as an anonymous module, so if you're using only the core (no locales / plugins), then you don't need config if you put it on a non-standard location.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/nuget/" name="/use-it/nuget/"></a>
<h3 class="docs-method-title" id="NuGet"> <a href="#/use-it/nuget/">NuGet</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/05-nuget.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<p><a href="javascript:window.open('https://www.nuget.org/');" target="_blank" rel="noopener noreferrer">NuGet <i class="fa fa-external-link"></i></a> / <a href="javascript:window.open('https://www.nuget.org/packages/Moment.js/');" target="_blank" rel="noopener noreferrer">Moment.js <i class="fa fa-external-link"></i></a></p>
<pre class="notranslate"><code>Install-Package Moment.js
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/meteor/" name="/use-it/meteor/"></a>
<h3 class="docs-method-title" id="meteor"> <a href="#/use-it/meteor/">meteor</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/06-meteor.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<p><a href="javascript:window.open('https://www.meteor.com/');" target="_blank" rel="noopener noreferrer">meteor <i class="fa fa-external-link"></i></a> / <a href="javascript:window.open('https://atmospherejs.com/');" target="_blank" rel="noopener noreferrer">atmosphere <i class="fa fa-external-link"></i></a> / <a href="javascript:window.open('https://atmospherejs.com/momentjs/moment');" target="_blank" rel="noopener noreferrer">momentjs:moment <i class="fa fa-external-link"></i></a></p>
<pre class="notranslate"><code>meteor add momentjs:moment
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/browserify/" name="/use-it/browserify/"></a>
<h3 class="docs-method-title" id="Browserify"> <a href="#/use-it/browserify/">Browserify</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/07-browserify.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<pre class="notranslate"><code>npm install moment
</code></pre>
<pre class="notranslate"><code class="language-javascript">var moment = require('moment');
moment().format();
</code></pre>
<p><strong>Note:</strong> There is a bug that prevents <code class="notranslate">moment.locale</code> from being loaded.</p>
<pre class="notranslate"><code class="language-javascript">var moment = require('moment');
moment.locale('cs');
console.log(moment.locale()); // en
</code></pre>
<p>Use the workaround below</p>
<pre class="notranslate"><code class="language-javascript">var moment = require('moment');
require('moment/locale/cs');
console.log(moment.locale()); // cs
</code></pre>
<p>In order to include all the locales</p>
<pre class="notranslate"><code class="language-javascript">var moment = require('moment');
require("moment/min/locales.min");
moment.locale('cs');
console.log(moment.locale()); // cs
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/webpack/" name="/use-it/webpack/"></a>
<h3 class="docs-method-title" id="Webpack"> <a href="#/use-it/webpack/">Webpack</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/08-webpack.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<pre class="notranslate"><code>npm install moment
</code></pre>
<pre class="notranslate"><code class="language-javascript">var moment = require('moment');
moment().format();
</code></pre>
<p><strong>Note:</strong> By default, webpack bundles <em>all</em> Moment.js locales (in Moment.js 2.18.1, that’s 160 minified KBs). To strip unnecessary locales and bundle only the used ones, add <a href="javascript:window.open('https://www.npmjs.com/package/moment-locales-webpack-plugin');" target="_blank" rel="noopener noreferrer"><code class="notranslate">moment-locales-webpack-plugin</code> <i class="fa fa-external-link"></i></a>:</p>

<pre class="notranslate"><code class="language-javascript">// webpack.config.js
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');

module.exports = {
    plugins: [
        // To strip all locales except “en”
        new MomentLocalesPlugin(),

        // Or: To strip all locales except “en”, “es-us” and “ru”
        // (“en” is built into Moment and can’t be removed)
        new MomentLocalesPlugin({
            localesToKeep: ['es-us', 'ru'],
        }),
    ],
};
</code></pre>
<p>There are other resources to optimize Moment.js with webpack, <a href="javascript:window.open('https://github.com/jmblog/how-to-optimize-momentjs-with-webpack');" target="_blank" rel="noopener noreferrer">for example this one <i class="fa fa-external-link"></i></a>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/typescript/" name="/use-it/typescript/"></a>
<h3 class="docs-method-title" id="Typescript-2.13.0+"> <a href="#/use-it/typescript/">Typescript</a> <span>2.13.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/09-typescript.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<p>As of version <strong>2.13.0</strong>, Moment includes a typescript definition file.</p>
<p>Install via NPM</p>
<pre class="notranslate"><code>npm install moment
</code></pre>
<p>Import and use in your Typescript file</p>

<pre class="notranslate"><code class="language-javascript">import moment = require('moment');

let now = moment().format('LLLL');
</code></pre>
<p><strong>Note:</strong> If you have trouble importing moment</p>
<p>For <em>Typescript 2.x</em> try adding <code class="notranslate">"moduleResolution": "node"</code> in <code class="notranslate">compilerOptions</code> in your <code class="notranslate">tsconfig.json</code> file</p>
<p>For <em>Typescript 1.x</em> try adding <code class="notranslate">"allowSyntheticDefaultImports": true</code> in <code class="notranslate">compilerOptions</code> in your <code class="notranslate">tsconfig.json</code> file and then use the syntax</p>

<pre class="notranslate"><code class="language-javascript">import moment from 'moment';
</code></pre>
<p><strong>Locale Import</strong></p>
<p>To use <code class="notranslate">moment.locale</code> you first need to import the language you are targeting.</p>

<pre class="notranslate"><code class="language-javascript">import * as moment from 'moment';
import 'moment/locale/pt-br';

console.log(moment.locale()); // en
moment.locale('fr');
console.log(moment.locale()); // fr
moment.locale('pt-br');
console.log(moment.locale()); // pt-br
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/system-js/" name="/use-it/system-js/"></a>
<h3 class="docs-method-title" id="System.js"> <a href="#/use-it/system-js/">System.js</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/10-system-js.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<p>To load moment, place it in the path specified by your System.config in the baseURL configuration. Then import it into your page.</p>

<pre class="notranslate"><code class="language-js">&lt;script src="system.js"&gt;&lt;/script&gt;
&lt;script&gt;
  System.config({
    baseURL: '/app'
  });

  System.import('moment.js');
 &lt;/script&gt;
</code></pre>
<p>If you need moment to be loaded as global, you can do this with the meta configuration:</p>

<pre class="notranslate"><code class="language-javascript">System.config({
  meta: {
    'moment': { format: 'global' }
  }
});
</code></pre>
<p>Alternatively, to provide Moment as a global to only a specific dependency, you can do this:</p>

<pre class="notranslate"><code class="language-javascript">System.config({
  meta: {
    'path/to/global-file.js': {
      globals: {
        moment: 'moment'
      }
    }
  }
});
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/other/" name="/use-it/other/"></a>
<h3 class="docs-method-title" id="Other"> <a href="#/use-it/other/">Other</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/11-other.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<p>To use under <strong>Java/Rhino</strong>, see <a href="javascript:window.open('https://gist.github.com/UnquietCode/5614860');" target="_blank" rel="noopener noreferrer">these instructions <i class="fa fa-external-link"></i></a>.</p>
<p>To use in <strong>Demandware</strong>, see <a href="javascript:window.open('https://github.com/moment/moment/issues/1034');" target="_blank" rel="noopener noreferrer">these instructions <i class="fa fa-external-link"></i></a>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/use-it/troubleshooting/" name="/use-it/troubleshooting/"></a>
<h3 class="docs-method-title" id="Troubleshooting"> <a href="#/use-it/troubleshooting/">Troubleshooting</a> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/00-use-it/12-troubleshooting.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<p>If you are having any troubles, the first place to check is the <a href="javascript:window.open('https://momentjs.com/guides');" target="_blank" rel="noopener noreferrer">guides <i class="fa fa-external-link"></i></a>.</p>
<p>If you don't find what you are looking for there, try asking a question on <a href="javascript:window.open('https://stackoverflow.com/questions/tagged/momentjs');" target="_blank" rel="noopener noreferrer">Stack Overflow <i class="fa fa-external-link"></i></a> with the <code class="notranslate">momentjs</code> tag.</p>
<p>Note: More than half of the issues seen on Stack Overflow can be answered by <a href="javascript:window.open('https://maggiepint.com/2016/05/14/moment-js-shows-the-wrong-date/');" target="_blank" rel="noopener noreferrer">this blog post <i class="fa fa-external-link"></i></a>.</p>
<p>You can also use the <a href="javascript:window.open('https://github.com/moment/moment/issues');" target="_blank" rel="noopener noreferrer">GitHub issue tracker <i class="fa fa-external-link"></i></a> to find related issues or open a new issue.</p>
<p>In addition, Moment has a <a href="javascript:window.open('https://gitter.im/moment/moment');" target="_blank" rel="noopener noreferrer">Gitter <i class="fa fa-external-link"></i></a> where the internal team is frequently available.</p>
<p>For general troubleshooting help, <a href="javascript:window.open('https://stackoverflow.com/questions/tagged/momentjs');" target="_blank" rel="noopener noreferrer">Stack Overflow <i class="fa fa-external-link"></i></a> is the preferred forum. Moment's maintainers are very active on Stack Overflow, as are several other knowledgeable users. The fastest response will be there.</p>
</div>
</article>
<article class="docs-section">
<a class="docs-section-target" id="/parsing/" name="/parsing/"></a>
<h2 class="docs-section-title" id="Parse"><a href="#/parsing/">Parse</a></h2>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/intro/" name="/parsing/intro/"></a>
<div class="docs-method-prose">
<p>Instead of modifying the native <code class="notranslate">Date.prototype</code>, Moment.js creates a wrapper for the <code class="notranslate">Date</code> object. To get this wrapper object, simply call <code class="notranslate">moment()</code> with one of the supported input types.</p>
<p>The <code class="notranslate">Moment</code> prototype is exposed through <code class="notranslate">moment.fn</code>. If you want to add your own functions, that is where you would put them.</p>
<p>For ease of reference, any method on the <code class="notranslate">Moment.prototype</code> will be referenced in the docs as <code class="notranslate">moment#method</code>. So <code class="notranslate">Moment.prototype.format</code> == <code class="notranslate">moment.fn.format</code> == <code class="notranslate">moment#format</code>.</p>
<p><strong>Please read:</strong></p>
<ul>
<li><code class="notranslate">moment(...)</code> is local mode. Ambiguous input (without offset) is assumed to be local time. Unambiguous input (with offset) is adjusted to local time.</li>
<li><code class="notranslate">moment.utc(...)</code> is utc mode. Ambiguous input is assumed to be UTC. Unambiguous input is adjusted to UTC.</li>
<li><code class="notranslate">moment.parseZone()</code> keep the input zone passed in. If the input is ambiguous, it is the same as local mode.</li>
<li><code class="notranslate">moment.tz(...)</code> with the moment-timezone plugin can parse input in a specific time zone.</li>
</ul>
<p>Keep in mind that a time zone and a time zone offset are two different things. An offset of -08:00 doesn't necessarily mean you are in the US Pacific time zone.</p>
<p><a href="javascript:window.open('https://momentjs.com/guides/#/parsing/');" target="_blank" rel="noopener noreferrer">See the Parsing Guide for additional information <i class="fa fa-external-link"></i></a>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/now/" name="/parsing/now/"></a>
<h3 class="docs-method-title" id="Now-1.0.0+"> <a href="#/parsing/now/">Now</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/01-now.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment();
moment(undefined);
// From 2.14.0 onward, also supported
moment([]);
moment({});
</code></pre>
</div>
<p>To get the current date and time, just call <code class="notranslate">moment()</code> with no parameters.</p>
<pre class="notranslate"><code class="language-javascript">var now = moment();
</code></pre>
<p>This is essentially the same as calling <code class="notranslate">moment(new Date())</code>.</p>
<p><strong>Note:</strong> From version <strong>2.14.0</strong>, <code class="notranslate">moment([])</code> and <code class="notranslate">moment({})</code> also return now. They used to default to start-of-today before 2.14.0, but that was arbitrary so it was changed.</p>
<p><strong>Note:</strong> Function parameters default to <code class="notranslate">undefined</code> when not passed in. Moment treats <code class="notranslate">moment(undefined)</code> as <code class="notranslate">moment()</code>.</p>
<pre class="notranslate"><code class="language-javascript">var x = undefined;
moment(x).isSame(moment(), 'second'); // true
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/string/" name="/parsing/string/"></a>
<h3 class="docs-method-title" id="String-1.0.0+"> <a href="#/parsing/string/">String</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/02-string.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(String);
</code></pre>
</div>
<p>When creating a moment from a string, we first check if the string matches known <a href="javascript:window.open('https://en.wikipedia.org/wiki/ISO_8601');" target="_blank" rel="noopener noreferrer">ISO 8601 <i class="fa fa-external-link"></i></a> formats, we then check if the string matches the <a href="javascript:window.open('https://tools.ietf.org/html/rfc2822#section-3.3');" target="_blank" rel="noopener noreferrer">RFC 2822 Date time <i class="fa fa-external-link"></i></a> format before dropping to the fall back of <code class="notranslate">new Date(string)</code> if a known format is not found.</p>
<pre class="notranslate"><code class="language-javascript">var day = moment("1995-12-25");
</code></pre>
<p><strong>Warning:</strong> Browser support for parsing strings <a href="javascript:window.open('http://dygraphs.com/date-formats.html');" target="_blank" rel="noopener noreferrer">is inconsistent <i class="fa fa-external-link"></i></a>. Because there is no specification on which formats should be supported, what works in some browsers will not work in other browsers.</p>

<p>For consistent results parsing anything other than ISO 8601 strings, you should use <a href="#/parsing/string-format/">String + Format</a>.</p>
<h4 id="Supported-ISO-8601-strings">Supported ISO 8601 strings</h4>
<p>An ISO 8601 string requires a date part.</p>
<pre class="notranslate"><code>2013-02-08  # A calendar date part
2013-02     # A month date part
2013-W06-5  # A week date part
2013-039    # An ordinal date part

20130208    # Basic (short) full date
201303      # Basic (short) year+month
2013        # Basic (short) year only
2013W065    # Basic (short) week, weekday
2013W06     # Basic (short) week only
2013050     # Basic (short) ordinal date (year + day-of-year)
</code></pre>
<p>A time part can also be included, separated from the date part by a space or an uppercase T.</p>
<pre class="notranslate"><code>2013-02-08T09            # An hour time part separated by a T
2013-02-08 09            # An hour time part separated by a space
2013-02-08 09:30         # An hour and minute time part
2013-02-08 09:30:26      # An hour, minute, and second time part
2013-02-08 09:30:26.123  # An hour, minute, second, and millisecond time part
2013-02-08 24:00:00.000  # hour 24, minute, second, millisecond equal 0 means next day at midnight

20130208T080910,123      # Short date and time up to ms, separated by comma
20130208T080910.123      # Short date and time up to ms
20130208T080910          # Short date and time up to seconds
20130208T0809            # Short date and time up to minutes
20130208T08              # Short date and time, hours only
</code></pre>
<p>Any of the date parts can have a time part.</p>
<pre class="notranslate"><code>2013-02-08 09  # A calendar date part and hour time part
2013-W06-5 09  # A week date part and hour time part
2013-039 09    # An ordinal date part and hour time part
</code></pre>
<p>If a time part is included, an offset from UTC can also be included as <code class="notranslate">+-HH:mm</code>, <code class="notranslate">+-HHmm</code>, <code class="notranslate">+-HH</code> or <code class="notranslate">Z</code>.</p>
<pre class="notranslate"><code>2013-02-08 09+07:00            # +-HH:mm
2013-02-08 09-0100             # +-HHmm
2013-02-08 09Z                 # Z
2013-02-08 09:30:26.123+07:00  # +-HH:mm
2013-02-08 09:30:26.123+07     # +-HH
</code></pre>
<p><strong>Note:</strong> Support for the week and ordinal formats was added in version <strong>2.3.0</strong>.</p>
<p>If a string does not match any of the above formats and is not able to be parsed with <code class="notranslate">Date.parse</code>, <code class="notranslate">moment#isValid</code> will return false.</p>
<pre class="notranslate"><code class="language-javascript">moment("not a real date").isValid(); // false
</code></pre>
<h4 id="The-RFC-2822-date-time-format">The RFC 2822 date time format</h4>
<p>Before parsing a RFC 2822 date time the string is cleansed to remove any comments and/or newline characters. The additional characters are legal in the format but add nothing to creating a valid moment instance.</p>
<p>After cleansing, the string is validated in the following space-separated sections, all using the English language:</p>
<pre class="notranslate"><code>6 Mar 17 21:22 UT
6 Mar 17 21:22:23 UT
6 Mar 2017 21:22:23 GMT
06 Mar 2017 21:22:23 Z
Mon 06 Mar 2017 21:22:23 z
Mon, 06 Mar 2017 21:22:23 +0000
</code></pre>
<ol>
<li>Day of Week in three letters, followed by an optional comma. (optional)</li>
<li>Day of Month (1 or 2 digit), followed by a three-letter month and 2 or 4 digit year</li>
<li>Two-digit hours and minutes separated by a colon (:), followed optionally by another colon and seconds in 2-digits</li>
<li>Timezone or offset in one of the following formats:</li>
<li>UT : +0000</li>
<li>GMT : +0000</li>
<li>EST | CST | MST | PST | EDT | CDT | MDT | PDT : US time zones*</li>
<li>A - I | K - Z : Military time zones*</li>
<li>Time offset +/-9999</li>
</ol>
<p>[*] See <a href="javascript:window.open('https://tools.ietf.org/html/rfc2822#section-4.3');" target="_blank" rel="noopener noreferrer">section 4.3 <i class="fa fa-external-link"></i></a> of the specification for details.</p>
<p>The parser also confirms that the day-of-week (when included) is consistent with the date.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/string-format/" name="/parsing/string-format/"></a>
<h3 class="docs-method-title" id="String-+-Format-1.0.0+"> <a href="#/parsing/string-format/">String + Format</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/03-string-format.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(String, String);
moment(String, String, String);
moment(String, String, String[]);
moment(String, String, Boolean);
moment(String, String, String, Boolean);
</code></pre>
</div>
<p>If you know the format of an input string, you can use that to parse a moment.</p>
<pre class="notranslate"><code class="language-javascript">moment("12-25-1995", "MM-DD-YYYY");
</code></pre>
<p>The parser ignores non-alphanumeric characters by default, so both of the following will return the same thing.</p>
<pre class="notranslate"><code class="language-javascript">moment("12-25-1995", "MM-DD-YYYY");
moment("12/25/1995", "MM-DD-YYYY");
</code></pre>
<p>You may get unexpected results when parsing both date and time. The below example may not parse as you expect:</p>
<pre class="notranslate"><code class="language-javascript">moment('24/12/2019 09:15:00', "DD MM YYYY hh:mm:ss");
</code></pre>
<p>You can use strict mode, which will identify the parsing error and set the Moment object as invalid:</p>
<pre class="notranslate"><code class="language-javascript">moment('24/12/2019 09:15:00', "DD MM YYYY hh:mm:ss", true);
</code></pre>
<p>The parsing tokens are similar to the formatting tokens used in <code class="notranslate">moment#format</code>.</p>
<h4 id="Year,-month,-and-day-tokens">Year, month, and day tokens</h4>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr>
<th>Input</th>
<th>Example</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="notranslate">YYYY</code></td>
<td><code class="notranslate">2014</code></td>
<td>4 or 2 digit year. Note: Only 4 digit can be parsed on <code class="notranslate">strict</code> mode</td>
</tr>
<tr>
<td><code class="notranslate">YY</code></td>
<td><code class="notranslate">14</code></td>
<td>2 digit year</td>
</tr>
<tr>
<td><code class="notranslate">Y</code></td>
<td><code class="notranslate">-25</code></td>
<td>Year with any number of digits and sign</td>
</tr>
<tr>
<td><code class="notranslate">Q</code></td>
<td><code class="notranslate">1..4</code></td>
<td>Quarter of year. Sets month to first month in quarter.</td>
</tr>
<tr>
<td><code class="notranslate">M MM</code></td>
<td><code class="notranslate">1..12</code></td>
<td>Month number</td>
</tr>
<tr>
<td><code class="notranslate">MMM MMMM</code></td>
<td><code class="notranslate">Jan..December</code></td>
<td>Month name in locale set by <code class="notranslate">moment.locale()</code></td>
</tr>
<tr>
<td><code class="notranslate">D DD</code></td>
<td><code class="notranslate">1..31</code></td>
<td>Day of month</td>
</tr>
<tr>
<td><code class="notranslate">Do</code></td>
<td><code class="notranslate">1st..31st</code></td>
<td>Day of month with ordinal</td>
</tr>
<tr>
<td><code class="notranslate">DDD DDDD</code></td>
<td><code class="notranslate">1..365</code></td>
<td>Day of year</td>
</tr>
<tr>
<td><code class="notranslate">X</code></td>
<td><code class="notranslate">1410715640.579</code></td>
<td>Unix timestamp</td>
</tr>
<tr>
<td><code class="notranslate">x</code></td>
<td><code class="notranslate">1410715640579</code></td>
<td>Unix ms timestamp</td>
</tr>
</tbody>
</table>
<p><code class="notranslate">YYYY</code> from version <strong>2.10.5</strong> supports 2 digit years, and converts them to a year near 2000 (same as <code class="notranslate">YY</code>).</p>
<p><code class="notranslate">Y</code> was added in <strong>2.11.1</strong>. It will match any number, signed or unsigned. It is useful for years that are not 4 digits or are before the common era. It can be used for any year.</p>
<h4 id="Week-year,-week,-and-weekday-tokens">Week year, week, and weekday tokens</h4>
<p>For these, the lowercase tokens use the locale aware week start days, and the uppercase tokens use the <a href="javascript:window.open('https://en.wikipedia.org/wiki/ISO_week_date');" target="_blank" rel="noopener noreferrer">ISO week date <i class="fa fa-external-link"></i></a> start days.</p>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr>
<th>Input</th>
<th>Example</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="notranslate">gggg</code></td>
<td><code class="notranslate">2014</code></td>
<td>Locale 4 digit week year</td>
</tr>
<tr>
<td><code class="notranslate">gg</code></td>
<td><code class="notranslate">14</code></td>
<td>Locale 2 digit week year</td>
</tr>
<tr>
<td><code class="notranslate">w ww</code></td>
<td><code class="notranslate">1..53</code></td>
<td>Locale week of year</td>
</tr>
<tr>
<td><code class="notranslate">e</code></td>
<td><code class="notranslate">0..6</code></td>
<td>Locale day of week</td>
</tr>
<tr>
<td><code class="notranslate">ddd dddd</code></td>
<td><code class="notranslate">Mon...Sunday</code></td>
<td>Day name in locale set by <code class="notranslate">moment.locale()</code></td>
</tr>
<tr>
<td><code class="notranslate">GGGG</code></td>
<td><code class="notranslate">2014</code></td>
<td>ISO 4 digit week year</td>
</tr>
<tr>
<td><code class="notranslate">GG</code></td>
<td><code class="notranslate">14</code></td>
<td>ISO 2 digit week year</td>
</tr>
<tr>
<td><code class="notranslate">W WW</code></td>
<td><code class="notranslate">1..53</code></td>
<td>ISO week of year</td>
</tr>
<tr>
<td><code class="notranslate">E</code></td>
<td><code class="notranslate">1..7</code></td>
<td>ISO day of week</td>
</tr>
</tbody>
</table>
<h4 id="Locale-aware-formats">Locale aware formats</h4>
<p>Locale aware date and time formats are also available using <code class="notranslate">LT LTS L LL LLL LLLL</code>. They were added in version <strong>2.2.1</strong>, except <code class="notranslate">LTS</code> which was added <strong>2.8.4</strong>.</p>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr>
<th>Input</th>
<th>Example</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="notranslate">L</code></td>
<td><code class="notranslate">04/09/1986</code></td>
<td>Date (in local format)</td>
</tr>
<tr>
<td><code class="notranslate">LL</code></td>
<td><code class="notranslate">September 4 1986</code></td>
<td>Month name, day of month, year</td>
</tr>
<tr>
<td><code class="notranslate">LLL</code></td>
<td><code class="notranslate">September 4 1986 8:30 PM</code></td>
<td>Month name, day of month, year, time</td>
</tr>
<tr>
<td><code class="notranslate">LLLL</code></td>
<td><code class="notranslate">Thursday, September 4 1986 8:30 PM</code></td>
<td>Day of week, month name, day of month, year, time</td>
</tr>
<tr>
<td><code class="notranslate">LT</code></td>
<td><code class="notranslate">8:30 PM</code></td>
<td>Time (without seconds)</td>
</tr>
<tr>
<td><code class="notranslate">LTS</code></td>
<td><code class="notranslate">8:30:00 PM</code></td>
<td>Time (with seconds)</td>
</tr>
</tbody>
</table>
<h4 id="Hour,-minute,-second,-millisecond,-and-offset-tokens">Hour, minute, second, millisecond, and offset tokens</h4>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr>
<th>Input</th>
<th>Example</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="notranslate">H HH</code></td>
<td><code class="notranslate">0..23</code></td>
<td>Hours (24 hour time)</td>
</tr>
<tr>
<td><code class="notranslate">h hh</code></td>
<td><code class="notranslate">1..12</code></td>
<td>Hours (12 hour time used with <code class="notranslate">a A</code>.)</td>
</tr>
<tr>
<td><code class="notranslate">k kk</code></td>
<td><code class="notranslate">1..24</code></td>
<td>Hours (24 hour time from 1 to 24)</td>
</tr>
<tr>
<td><code class="notranslate">a A</code></td>
<td><code class="notranslate">am pm</code></td>
<td>Post or ante meridiem (Note the one character <code class="notranslate">a p</code> are also considered valid)</td>
</tr>
<tr>
<td><code class="notranslate">m mm</code></td>
<td><code class="notranslate">0..59</code></td>
<td>Minutes</td>
</tr>
<tr>
<td><code class="notranslate">s ss</code></td>
<td><code class="notranslate">0..59</code></td>
<td>Seconds</td>
</tr>
<tr>
<td><code class="notranslate">S SS SSS ... SSSSSSSSS</code></td>
<td><code class="notranslate">0..999999999</code></td>
<td>Fractional seconds</td>
</tr>
<tr>
<td><code class="notranslate">Z ZZ</code></td>
<td><code class="notranslate">+12:00</code></td>
<td>Offset from UTC as <code class="notranslate">+-HH:mm</code>, <code class="notranslate">+-HHmm</code>, or <code class="notranslate">Z</code></td>
</tr>
</tbody>
</table>
<p>From version <strong>2.10.5</strong>: fractional second tokens length 4 up to 9 can parse any number of digits, but will only consider the top 3 (milliseconds). Use if you have the time printed with many fractional digits and want to consume the input.</p>
<p>Note that the number of <code class="notranslate">S</code> characters provided is only relevant when parsing in strict mode. In standard mode, <code class="notranslate">S</code>, <code class="notranslate">SS</code>, <code class="notranslate">SSS</code>, <code class="notranslate">SSSS</code> are all equivalent, and interpreted as fractions of a second. For example, <code class="notranslate">.12</code> is always 120 milliseconds, passing <code class="notranslate">SS</code> will not cause it to be interpreted as 12 milliseconds.</p>
<p><code class="notranslate">Z ZZ</code> were added in version <strong>1.2.0</strong>.</p>
<p><code class="notranslate">S SS SSS</code> were added in version <strong>1.6.0</strong>.</p>
<p><code class="notranslate">X</code> was added in version <strong>2.0.0</strong>.</p>
<p><code class="notranslate">SSSSS ... SSSSSSSSS</code> were added in version <strong>2.10.5</strong>.</p>
<p><code class="notranslate">k kk</code> were added in version <strong>2.13.0</strong>.</p>
<p>Unless you specify a time zone offset, parsing a string will create a date in the current time zone.</p>
<pre class="notranslate"><code class="language-js">moment("2010-10-20 4:30",       "YYYY-MM-DD HH:mm");   // parsed as 4:30 local time
moment("2010-10-20 4:30 +0000", "YYYY-MM-DD HH:mm Z"); // parsed as 4:30 UTC
</code></pre>
<h4 id="Era-Year-related-tokens">Era Year related tokens</h4>
<p><em>Tokens are case-sensitive.</em></p>
<table>
<thead>
<tr>
<th>Input</th>
<th>Examples</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>y .. yyyy</td>
<td><code class="notranslate">5 +5 -500</code></td>
<td>Years</td>
</tr> 
<tr>
<td>yo</td>
<td><code class="notranslate">5th 1st</code></td>
<td>Ordinal Years</td>
</tr>
<tr>
<td>N</td>
<td><code class="notranslate">AD</code></td>
<td>Abbr Era name</td>
</tr>
<tr>
<td>NN</td>
<td><code class="notranslate">AD</code></td>
<td>Short Era name</td>
</tr>
<tr>
<td>NNN</td>
<td><code class="notranslate">Anno Domini</code></td>
<td>Full Era name</td>
</tr>
</tbody>
</table>
<p>Era support was added in <strong>2.25.0</strong>. The tokens/API are still in flux.</p>
<h4 id="Notes-and-gotchas">Notes and gotchas</h4>
<p>If the moment that results from the parsed input does not exist, <code class="notranslate">moment#isValid</code> will return false.</p>
<pre class="notranslate"><code class="language-js">moment("2010 13",           "YYYY MM").isValid();     // false (not a real month)
moment("2010 11 31",        "YYYY MM DD").isValid();  // false (not a real day)
moment("2010 2 29",         "YYYY MM DD").isValid();  // false (not a leap year)
moment("2010 notamonth 29", "YYYY MMM DD").isValid(); // false (not a real month name)
</code></pre>
<p>As of version <strong>2.0.0</strong>, a locale key can be passed as the third parameter to <code class="notranslate">moment()</code> and <code class="notranslate">moment.utc()</code>.</p>
<pre class="notranslate"><code class="language-js">moment('2012 juillet', 'YYYY MMM', 'fr');
moment('2012 July',    'YYYY MMM', 'en');
moment('2012 July',    'YYYY MMM', ['qj', 'en']);
</code></pre>
<p>Moment's parser is very forgiving, and this can lead to undesired/unexpected behavior.</p>
<p>For example, the following behavior can be observed:</p>
<pre class="notranslate"><code class="language-javascript">moment('2016 is a date', 'YYYY-MM-DD').isValid() //true, 2016 was matched
</code></pre>
<p>Previous to <strong>2.13.0</strong> the parser exhibited the following behavior. This has been corrected.</p>
<pre class="notranslate"><code class="language-javascript">moment('I am spartacus', 'h:hh A').isValid();     //true - the 'am' matches the 'A' flag.
</code></pre>
<p>As of version <strong>2.3.0</strong>, you may specify a boolean for the last argument to make Moment use strict parsing. Strict parsing requires that the format and input match exactly, <em>including delimeters</em>.</p>
<pre class="notranslate"><code class="language-javascript">moment('It is 2012-05-25', 'YYYY-MM-DD').isValid();       // true
moment('It is 2012-05-25', 'YYYY-MM-DD', true).isValid(); // false
moment('2012-05-25',       'YYYY-MM-DD', true).isValid(); // true
moment('2012.05.25',       'YYYY-MM-DD', true).isValid(); // false
</code></pre>
<p>You can use both locale and strictness.</p>
<pre class="notranslate"><code class="language-javascript">moment('2012-10-14', 'YYYY-MM-DD', 'fr', true);
</code></pre>
<p>Strict parsing is frequently the best parsing option. For more information about choosing strict vs forgiving parsing, see the <a href="javascript:window.open('https://momentjs.com/guides/#/parsing/');" target="_blank" rel="noopener noreferrer">parsing guide. <i class="fa fa-external-link"></i></a></p>
<h4 id="Parsing-two-digit-years">Parsing two digit years</h4>
<p>By default, two digit years above 68 are assumed to be in the 1900's and years 68 or below are assumed to be in the 2000's. This can be changed by replacing the <code class="notranslate">moment.parseTwoDigitYear</code> method. The only argument of this method is a string containing the two years input by the user, and should return the year as an integer.</p>
<pre class="notranslate"><code class="language-javascript">moment.parseTwoDigitYear = function(yearString) {
    return parseInt(yearString) + 2000;
}
</code></pre>
<h4 id="Parsing-glued-hour-and-minutes">Parsing glued hour and minutes</h4>
<p>From version <strong>2.11.0</strong> parsing <code class="notranslate">hmm</code>, <code class="notranslate">Hmm</code>, <code class="notranslate">hmmss</code> and <code class="notranslate">Hmmss</code> is supported:</p>
<pre class="notranslate"><code class="language-javascript">moment("123", "hmm").format("HH:mm") === "01:23"
moment("1234", "hmm").format("HH:mm") === "12:34"
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/string-formats/" name="/parsing/string-formats/"></a>
<h3 class="docs-method-title" id="String-+-Formats-1.0.0+"> <a href="#/parsing/string-formats/">String + Formats</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/04-string-formats.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(String, String[], String, Boolean);
</code></pre>
</div>
<p>If you don't know the exact format of an input string, but know it could be one of many, you can use an array of formats.</p>
<p>This is the same as <a href="#/parsing/string-format/">String + Format</a>, only it will try to match the input to multiple formats.</p>
<pre class="notranslate"><code class="language-js">moment("12-25-1995", ["MM-DD-YYYY", "YYYY-MM-DD"]);
</code></pre>
<p>Starting in version <strong>2.3.0</strong>, Moment uses some simple heuristics to determine which format to use. In order:</p>
<ul>
<li>Prefer formats resulting in <a href="#/parsing/is-valid/">valid</a> dates over invalid ones.</li>
<li>Prefer formats that parse more of the string than less and use more of the format than less, i.e. prefer stricter parsing.</li>
<li>Prefer formats earlier in the array than later.</li>
</ul>
<pre class="notranslate"><code class="language-js">moment("29-06-1995", ["MM-DD-YYYY", "DD-MM", "DD-MM-YYYY"]); // uses the last format
moment("05-06-1995", ["MM-DD-YYYY", "DD-MM-YYYY"]);          // uses the first format
</code></pre>
<p>You may also specify a locale and strictness argument. They work the same as the single format case.</p>
<pre class="notranslate"><code class="language-js">moment("29-06-1995", ["MM-DD-YYYY", "DD-MM-YYYY"], 'fr');       // uses 'fr' locale
moment("29-06-1995", ["MM-DD-YYYY", "DD-MM-YYYY"], true);       // uses strict parsing
moment("05-06-1995", ["MM-DD-YYYY", "DD-MM-YYYY"], 'fr', true); // uses 'fr' locale and strict parsing
</code></pre>
<p><strong>Note:</strong> Parsing multiple formats is considerably slower than parsing a single format. If you can avoid it, it is much faster to parse a single format.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/special-formats/" name="/parsing/special-formats/"></a>
<h3 class="docs-method-title" id="Special-Formats-2.7.0+"> <a href="#/parsing/special-formats/">Special Formats</a> <span>2.7.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/05-special-formats.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(String, moment.CUSTOM_FORMAT, [String], [Boolean]);
moment(String, moment.HTML5_FMT.DATETIME_LOCAL, [String], [Boolean]); // from 2.20.0
moment(String, [..., moment.ISO_8601, ...], [String], [Boolean]);
</code></pre>
</div>
<p><a href="javascript:window.open('https://en.wikipedia.org/wiki/ISO_8601');" target="_blank" rel="noopener noreferrer">ISO-8601 <i class="fa fa-external-link"></i></a> is a standard for time and duration display. Moment already supports parsing iso-8601 strings, but this can be specified explicitly in the format/list of formats when constructing a moment.</p>
<p>To specify iso-8601 parsing use <code class="notranslate">moment.ISO_8601</code> constant.</p>
<pre class="notranslate"><code class="language-javascript">moment("2010-01-01T05:06:07", moment.ISO_8601);
moment("2010-01-01T05:06:07", ["YYYY", moment.ISO_8601]);
</code></pre>
<p>As of version <strong>2.20.0</strong>, the following HTML5 formats are available as constants in the <code class="notranslate">moment</code> object's <code class="notranslate">HTML5_FMT</code> property (<code class="notranslate">moment.HTML5_FMT.*</code>):</p>
<table>
<thead>
<tr>
<th>Constant</th>
<th>Format</th>
<th>Example</th>
<th>Input Type</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="notranslate">DATETIME_LOCAL</code></td>
<td><code class="notranslate">YYYY-MM-DDTHH:mm</code></td>
<td>2017-12-14T16:34</td>
<td><code class="notranslate">&lt;input type="datetime-local" /&gt;</code></td>
</tr>
<tr>
<td><code class="notranslate">DATETIME_LOCAL_SECONDS</code></td>
<td><code class="notranslate">YYYY-MM-DDTHH:mm:ss</code></td>
<td>2017-12-14T16:34:10</td>
<td><code class="notranslate">&lt;input type="datetime-local" step="1" /&gt;</code></td>
</tr>
<tr>
<td><code class="notranslate">DATETIME_LOCAL_MS</code></td>
<td><code class="notranslate">YYYY-MM-DDTHH:mm:ss.SSS</code></td>
<td>2017-12-14T16:34:10.234</td>
<td><code class="notranslate">&lt;input type="datetime-local" step="0.001" /&gt;</code></td>
</tr>
<tr>
<td><code class="notranslate">DATE</code></td>
<td><code class="notranslate">YYYY-MM-DD</code></td>
<td>2017-12-14</td>
<td><code class="notranslate">&lt;input type="date" /&gt;</code></td>
</tr>
<tr>
<td><code class="notranslate">TIME</code></td>
<td><code class="notranslate">HH:mm</code></td>
<td>16:34</td>
<td><code class="notranslate">&lt;input type="time" /&gt;</code></td>
</tr>
<tr>
<td><code class="notranslate">TIME_SECONDS</code></td>
<td><code class="notranslate">HH:mm:ss</code></td>
<td>16:34:10</td>
<td><code class="notranslate">&lt;input type="time" step="1" /&gt;</code></td>
</tr>
<tr>
<td><code class="notranslate">TIME_MS</code></td>
<td><code class="notranslate">HH:mm:ss.SSS</code></td>
<td>16:34:10.234</td>
<td><code class="notranslate">&lt;input type="time" step="0.001" /&gt;</code></td>
</tr>
<tr>
<td><code class="notranslate">WEEK</code></td>
<td><code class="notranslate">GGGG-[W]WW</code></td>
<td>2017-W50</td>
<td><code class="notranslate">&lt;input type="week" /&gt;</code></td>
</tr>
<tr>
<td><code class="notranslate">MONTH</code></td>
<td><code class="notranslate">YYYY-MM</code></td>
<td>2017-12</td>
<td><code class="notranslate">&lt;input type="month" /&gt;</code></td>
</tr>
</tbody>
</table>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/object/" name="/parsing/object/"></a>
<h3 class="docs-method-title" id="Object-2.2.1+"> <a href="#/parsing/object/">Object</a> <span>2.2.1+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/06-object.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment({unit: value, ...});
</code></pre>
</div>
<pre class="notranslate"><code class="language-javascript">moment({ hour:15, minute:10 });
moment({ y    :2010, M     :3, d   :5, h    :15, m      :10, s      :3, ms          :123});
moment({ year :2010, month :3, day :5, hour :15, minute :10, second :3, millisecond :123});
moment({ years:2010, months:3, days:5, hours:15, minutes:10, seconds:3, milliseconds:123});
moment({ years:2010, months:3, date:5, hours:15, minutes:10, seconds:3, milliseconds:123});
moment({ years:'2010', months:'3', date:'5', hours:'15', minutes:'10', seconds:'3', milliseconds:'123'});  // from 2.11.0
</code></pre>
<p>You can create a moment by specifying some of the units in an object.</p>
<p>Omitted units default to 0 or the current date, month, and year.</p>
<p><code class="notranslate">day</code> and <code class="notranslate">date</code> key both mean day-of-the-month.</p>
<p><code class="notranslate">date</code> was added in <strong>2.8.4</strong>.</p>
<p>String values (as shown on the last line) are supported from version <strong>2.11.0</strong>.</p>
<p>Note that like <code class="notranslate">moment(Array)</code> and <code class="notranslate">new Date(year, month, date)</code>, months are 0 indexed.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/unix-timestamp-milliseconds/" name="/parsing/unix-timestamp-milliseconds/"></a>
<h3 class="docs-method-title" id="Unix-Timestamp-(milliseconds)-1.0.0+"> <a href="#/parsing/unix-timestamp-milliseconds/">Unix Timestamp (milliseconds)</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/07-unix-timestamp-milliseconds.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(Number);
</code></pre>
</div>
<p>Similar to <code class="notranslate">new Date(Number)</code>, you can create a moment by passing an integer value representing the number of <em>milliseconds</em> since the Unix Epoch (Jan 1 1970 12AM UTC).</p>
<pre class="notranslate"><code class="language-javascript">var day = moment(1318781876406);
</code></pre>
<p><a href="javascript:window.open('https://www.ecma-international.org/ecma-262/6.0/#sec-time-values-and-time-range');" target="_blank" rel="noopener noreferrer"> Note: ECMAScript calls this a "Time Value" <i class="fa fa-external-link"></i></a></p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/unix-timestamp/" name="/parsing/unix-timestamp/"></a>
<h3 class="docs-method-title" id="Unix-Timestamp-(seconds)-1.6.0+"> <a href="#/parsing/unix-timestamp/">Unix Timestamp (seconds)</a> <span>1.6.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/08-unix-timestamp.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment.unix(Number)
</code></pre>
</div>
<p>To create a moment from a Unix timestamp (<em>seconds</em> since the Unix Epoch), use <code class="notranslate">moment.unix(Number)</code>.</p>
<pre class="notranslate"><code class="language-javascript">var day = moment.unix(1318781876);
</code></pre>
<p>This is implemented as <code class="notranslate">moment(timestamp * 1000)</code>, so partial seconds in the input timestamp are included.</p>
<pre class="notranslate"><code class="language-javascript">var day = moment.unix(1318781876.721);
</code></pre>
<p><strong>Note:</strong> Despite Unix timestamps being UTC-based, this function creates a moment object in <em>local</em> mode. If you need UTC, then subsequently call <code class="notranslate">.utc()</code>, as in:</p>
<pre class="notranslate"><code class="language-javascript">var day = moment.unix(1318781876).utc();
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/date/" name="/parsing/date/"></a>
<h3 class="docs-method-title" id="Date-1.0.0+"> <a href="#/parsing/date/">Date</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/09-date.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(Date);
</code></pre>
</div>
<p>You can create a <code class="notranslate">Moment</code> with a pre-existing native Javascript <code class="notranslate">Date</code> object.</p>
<pre class="notranslate"><code class="language-javascript">var day = new Date(2011, 9, 16);
var dayWrapper = moment(day);
</code></pre>
<p>This clones the <code class="notranslate">Date</code> object; further changes to the <code class="notranslate">Date</code> won't affect the <code class="notranslate">Moment</code>, and vice-versa.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/array/" name="/parsing/array/"></a>
<h3 class="docs-method-title" id="Array-1.0.0+"> <a href="#/parsing/array/">Array</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/10-array.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(Number[]);
</code></pre>
</div>
<p>You can create a moment with an array of numbers that mirror the parameters passed to <a href="javascript:window.open('https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date');" target="_blank" rel="noopener noreferrer">new Date() <i class="fa fa-external-link"></i></a></p>
<p><code class="notranslate">[year, month, day, hour, minute, second, millisecond]</code></p>
<pre class="notranslate"><code class="language-javascript">moment([2010, 1, 14, 15, 25, 50, 125]); // February 14th, 3:25:50.125 PM
</code></pre>
<p>Any value past the year is optional, and will default to the lowest possible number.</p>
<pre class="notranslate"><code class="language-javascript">moment([2010]);        // January 1st
moment([2010, 6]);     // July 1st
moment([2010, 6, 10]); // July 10th
</code></pre>
<p>Construction with an array will create a date in the current time zone. To create a date from an array at UTC, use <code class="notranslate">moment.utc(Number[])</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment.utc([2010, 1, 14, 15, 25, 50, 125]);
</code></pre>
<p><strong>Note:</strong> Because this mirrors the native <code class="notranslate">Date</code> parameters, months, hours, minutes, seconds, and milliseconds are all zero indexed. Years and days of the month are 1 indexed.</p>
<p>This is often the cause of frustration, especially with months, so take note!</p>
<p>If the date represented by the array does not exist, <code class="notranslate">moment#isValid</code> will return false.</p>
<pre class="notranslate"><code class="language-javascript">moment([2010, 12]).isValid();     // false (not a real month)
moment([2010, 10, 31]).isValid(); // false (not a real day)
moment([2010, 1, 29]).isValid();  // false (not a leap year)
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/asp-net-json-date/" name="/parsing/asp-net-json-date/"></a>
<h3 class="docs-method-title" id="ASP.NET-JSON-Date-1.3.0+"> <a href="#/parsing/asp-net-json-date/">ASP.NET JSON Date</a> <span>1.3.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/11-asp-net-json-date.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(String);
</code></pre>
</div>
<p>Microsoft Web API returns JSON dates in proper ISO-8601 format by default, but older ASP.NET technologies may return dates in JSON as <code class="notranslate">/Date(1198908717056)/</code> or <code class="notranslate">/Date(1198908717056-0700)/</code></p>
<p>If a string that matches this format is passed in, it will be parsed correctly.</p>
<pre class="notranslate"><code class="language-javascript">moment("/Date(1198908717056-0700)/"); // 2007-12-28T23:11:57.056-07:00
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/moment-clone/" name="/parsing/moment-clone/"></a>
<h3 class="docs-method-title" id="Moment-Clone-1.2.0+"> <a href="#/parsing/moment-clone/">Moment Clone</a> <span>1.2.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/12-moment-clone.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment(Moment);
</code></pre>
</div>
<p>All moments are mutable. If you want a clone of a moment, you can do so implicitly or explicitly.</p>
<p>Calling <code class="notranslate">moment()</code> on a moment will clone it.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2012]);
var b = moment(a);
a.year(2000);
b.year(); // 2012
</code></pre>
<p>Additionally, you can call <code class="notranslate">moment#clone</code> to clone a moment.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2012]);
var b = a.clone();
a.year(2000);
b.year(); // 2012
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/utc/" name="/parsing/utc/"></a>
<h3 class="docs-method-title" id="UTC-1.5.0+"> <a href="#/parsing/utc/">UTC</a> <span>1.5.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/13-utc.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment.utc();
moment.utc(Number);
moment.utc(Number[]);
moment.utc(String);
moment.utc(String, String);
moment.utc(String, String[]);
moment.utc(String, String, String);
moment.utc(String, String, String[]);
moment.utc(String, String, Boolean);
moment.utc(String, String, String, Boolean);
moment.utc(Moment);
moment.utc(Date);
</code></pre>
</div>
<p>By default, moment parses and displays in local time.</p>
<p>If you want to parse or display a moment in UTC, you can use <code class="notranslate">moment.utc()</code> instead of <code class="notranslate">moment()</code>.</p>
<p>This brings us to an interesting feature of Moment.js. UTC mode.</p>
<p>While in UTC mode, all display methods will display in UTC time instead of local time.</p>
<pre class="notranslate"><code class="language-javascript">moment().format();     // 2013-02-04T10:35:24-08:00
moment.utc().format(); // 2013-02-04T18:35:24+00:00
</code></pre>
<p>Additionally, while in UTC mode, all getters and setters will internally use the <code class="notranslate">Date#getUTC*</code> and <code class="notranslate">Date#setUTC*</code> methods instead of the <code class="notranslate">Date#get*</code> and <code class="notranslate">Date#set*</code> methods.</p>
<pre class="notranslate"><code class="language-javascript">moment.utc().seconds(30).valueOf() === new Date().setUTCSeconds(30);
moment.utc().seconds()   === new Date().getUTCSeconds();
</code></pre>
<p>It is important to note that though the displays differ above, they are both the same moment in time.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment();
var b = moment.utc();
a.format();  // 2013-02-04T10:35:24-08:00
b.format();  // 2013-02-04T18:35:24+00:00
a.valueOf(); // 1360002924000
b.valueOf(); // 1360002924000
</code></pre>
<p>Any moment created with <code class="notranslate">moment.utc()</code> will be in UTC mode, and any moment created with <code class="notranslate">moment()</code> will not.</p>
<p>To switch from UTC to local time, you can use <a href="#/manipulating/utc/">moment#utc</a> or <a href="#/manipulating/local/">moment#local</a>.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment.utc([2011, 0, 1, 8]);
a.hours(); // 8 UTC
a.local();
a.hours(); // 0 PST
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/parse-zone/" name="/parsing/parse-zone/"></a>
<h3 class="docs-method-title" id="parseZone-2.3.0+"> <a href="#/parsing/parse-zone/">parseZone</a> <span>2.3.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/14-parse-zone.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment.parseZone()
moment.parseZone(String)
moment.parseZone(String, String)
moment.parseZone(String, [String])
moment.parseZone(String, String, Boolean)
moment.parseZone(String, String, String, Boolean)
</code></pre>
</div>
<p>Moment's string parsing functions like <code class="notranslate">moment(string)</code> and <code class="notranslate">moment.utc(string)</code> accept offset information if provided, but convert the resulting Moment object to local or UTC time. In contrast, <code class="notranslate">moment.parseZone()</code> parses the string but keeps the resulting Moment object in a fixed-offset timezone with the provided offset in the string.</p>
<pre class="notranslate"><code class="language-javascript">moment.parseZone("2013-01-01T00:00:00-13:00").utcOffset(); // -780 ("-13:00" in total minutes)
moment.parseZone('2013 01 01 05 -13:00', 'YYYY MM DD HH ZZ').utcOffset(); // -780  ("-13:00" in total minutes)
moment.parseZone('2013-01-01-13:00', ['DD MM YYYY ZZ', 'YYYY MM DD ZZ']).utcOffset(); // -780  ("-13:00" in total minutes);
</code></pre>
<p>It also allows you to pass locale and strictness arguments.</p>
<pre class="notranslate"><code class="language-javascript">moment.parseZone("2013 01 01 -13:00", 'YYYY MM DD ZZ', true).utcOffset(); // -780  ("-13:00" in total minutes)
moment.parseZone("2013-01-01-13:00", 'YYYY MM DD ZZ', true).utcOffset(); // NaN (doesn't pass the strictness check)
moment.parseZone("2013 01 01 -13:00", 'YYYY MM DD ZZ', 'fr', true).utcOffset(); // -780 (with locale and strictness argument)
moment.parseZone("2013 01 01 -13:00", ['DD MM YYYY ZZ', 'YYYY MM DD ZZ'], 'fr', true).utcOffset(); // -780 (with locale and strictness argument alongside an array of formats)
</code></pre>
<p><code class="notranslate">moment.parseZone</code> is equivalent to parsing the string and using <code class="notranslate">moment#utcOffset</code> to parse the zone.</p>
<pre class="notranslate"><code class="language-javascript">var s = "2013-01-01T00:00:00-13:00";
moment(s).utcOffset(s);
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/is-valid/" name="/parsing/is-valid/"></a>
<h3 class="docs-method-title" id="Validation-1.7.0+"> <a href="#/parsing/is-valid/">Validation</a> <span>1.7.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/15-is-valid.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isValid();
</code></pre>
</div>
<p>Moment applies stricter initialization rules than the <code class="notranslate">Date</code> constructor.</p>
<pre class="notranslate"><code class="language-js">new Date(2013, 25, 14).toString(); // "Sat Feb 14 2015 00:00:00 GMT-0500 (EST)"
moment([2015, 25, 35]).format();   // 'Invalid date'
</code></pre>
<p>You can check whether the Moment considers the date invalid using <code class="notranslate">moment#isValid</code>. You can check the metrics used by <code class="notranslate">#isValid</code> using <code class="notranslate">moment#parsingFlags</code>, which returns an object.</p>
<p>The following parsing flags result in an invalid date:</p>
<ul>
<li><code class="notranslate">overflow</code>: An overflow of a date field, such as a 13th month, a 32nd day of the month (or a 29th of February on non-leap years), a 367th day of the year, etc. <code class="notranslate">overflow</code> contains the index of the invalid unit to match <code class="notranslate">#invalidAt</code> (see below); <code class="notranslate">-1</code> means no overflow.</li>
<li><code class="notranslate">invalidMonth</code>: An invalid month name, such as <code class="notranslate">moment('Marbruary', 'MMMM');</code>. Contains the invalid month string itself, or else null.</li>
<li><code class="notranslate">empty</code>: An input string that contains nothing parsable, such as <code class="notranslate">moment('this is nonsense');</code>. Boolean.</li>
<li><code class="notranslate">nullInput</code>: A <code class="notranslate">null</code> input, like <code class="notranslate">moment(null);</code>. Boolean.</li>
<li><code class="notranslate">invalidFormat</code>: An empty list of formats, such as <code class="notranslate">moment('2013-05-25', [])</code>. Boolean.</li>
<li><code class="notranslate">userInvalidated</code>: A date created explicitly as invalid, such as <code class="notranslate">moment.invalid()</code>. Boolean.</li>
</ul>
<p>In addition to the above, As of <strong>2.13.0</strong> the meridiem and parsedDateParts flags work together to determine date validity.</p>
<ul>
<li><code class="notranslate">meridiem</code>: Indicates what meridiem (AM/PM) was parsed, if any. String.</li>
<li><code class="notranslate">parsedDateParts</code>: Returns an array of date parts parsed in descending order - i.e. parsedDateParts[0] === year. If no parts are present, but meridiem has value, date is invalid. Array.</li>
</ul>
<p>Additionally, if the Moment is parsed in strict mode, these flags must be empty for the Moment to be valid:</p>
<ul>
<li><code class="notranslate">unusedTokens</code>: array of format substrings not found in the input string</li>
<li><code class="notranslate">unusedInput</code>: array of input substrings not matched to the format string</li>
</ul>
<p><strong>Note:</strong> Moment's concept of validity became more strict and consistent between <strong>2.2</strong> and <strong>2.3</strong>. <strong>Note:</strong> Validity is determined on moment creation. A modified moment (i.e. <code class="notranslate">moment().hour(NaN)</code>) will remain valid.</p>
<p>Additionally, you can use <code class="notranslate">moment#invalidAt</code> to determine which date unit overflowed.</p>
<pre class="notranslate"><code class="language-javascript">var m = moment("2011-10-10T10:20:90");
m.isValid(); // false
m.invalidAt(); // 5 for seconds
</code></pre>
<p>The return value has the following meaning:</p>
<ol>
<li>years</li>
<li>months</li>
<li>days</li>
<li>hours</li>
<li>minutes</li>
<li>seconds</li>
<li>milliseconds</li>
</ol>
<p><strong>Note:</strong> In case of multiple wrong units the first one is returned (because days validity may depend on month, for example).</p>
<h2 id="Invalid-Moments">Invalid Moments</h2>
<p>If a moment is invalid, it behaves like a NaN in floating point operations.</p>
<p>All of the following produce invalid moments:</p>
<ul>
<li><code class="notranslate">invalid.add(unit, value)</code></li>
<li><code class="notranslate">another.add(invalid)</code></li>
<li><code class="notranslate">invalid.clone()</code></li>
<li><code class="notranslate">invalid.diff(another)</code></li>
<li><code class="notranslate">invalid.endOf(unit)</code></li>
<li><code class="notranslate">invalid.max(another)</code></li>
<li><code class="notranslate">another.max(invalid)</code></li>
<li><code class="notranslate">invalid.min(another)</code></li>
<li><code class="notranslate">another.min(invalid)</code></li>
<li><code class="notranslate">invalid.set(unit, value)</code></li>
<li><code class="notranslate">invalid.startOf(unit)</code></li>
<li><code class="notranslate">invalid.subtract(unit, value)</code></li>
</ul>
<p>The following produce a localized version of <code class="notranslate">'InvalidDate'</code>:</p>
<ul>
<li><code class="notranslate">invalid.format(anyFmt)</code> results in <code class="notranslate">'Invalid Date'</code> in the current locale</li>
<li><code class="notranslate">invalid.from(another)</code></li>
<li><code class="notranslate">another.from(invalid)</code></li>
<li><code class="notranslate">invalid.fromNow(suffix)</code></li>
<li><code class="notranslate">invalid.to(another)</code></li>
<li><code class="notranslate">another.to(invalid)</code></li>
<li><code class="notranslate">invalid.toNow(suffix)</code></li>
<li><code class="notranslate">invalid.toISOString()</code> (Before <strong>2.18.0</strong>)</li>
<li><code class="notranslate">invalid.toString()</code></li>
</ul>
<p>The following return <code class="notranslate">false</code>:</p>
<ul>
<li><code class="notranslate">invalid.isAfter(another)</code></li>
<li><code class="notranslate">invalid.isAfter(invalid)</code></li>
<li><code class="notranslate">another.isAfter(invalid)</code></li>
<li><code class="notranslate">invalid.isBefore(another)</code></li>
<li><code class="notranslate">invalid.isBefore(invalid)</code></li>
<li><code class="notranslate">another.isBefore(invalid)</code></li>
<li><code class="notranslate">invalid.isBetween(another, another)</code></li>
<li><code class="notranslate">invalid.isBetween(invalid, invalid)</code></li>
<li><code class="notranslate">invalid.isSame(another)</code></li>
<li><code class="notranslate">invalid.isSame(invalid)</code></li>
<li><code class="notranslate">another.isSame(invalid)</code></li>
<li><code class="notranslate">invalid.isSameOrAfter(another)</code></li>
<li><code class="notranslate">invalid.isSameOrAfter(invalid)</code></li>
<li><code class="notranslate">another.isSameOrAfter(invalid)</code></li>
<li><code class="notranslate">invalid.isSameOrBefore(another)</code></li>
<li><code class="notranslate">invalid.isSameOrBefore(invalid)</code></li>
<li><code class="notranslate">another.isSameOrBefore(invalid)</code></li>
</ul>
<p>And these return <code class="notranslate">null</code> or <code class="notranslate">NaN</code> with some structure:</p>
<ul>
<li><code class="notranslate">invalid.get(unit)</code> returns null, as all other named getters</li>
<li><code class="notranslate">invalid.toArray() === [NaN, NaN, NaN, NaN, NaN, NaN]</code></li>
<li><code class="notranslate">invalid.toObject()</code> has all values set to <code class="notranslate">NaN</code></li>
<li><code class="notranslate">invalid.toDate()</code> returns an invalid Date object</li>
<li><code class="notranslate">invalid.toJSON()</code> returns null</li>
<li><code class="notranslate">invalid.unix()</code> returns null</li>
<li><code class="notranslate">invalid.valueOf()</code> returns null</li>
<li><code class="notranslate">invalid.toISOString()</code> returns null (As of <strong>2.18.0</strong>)</li>
</ul>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/creation-data/" name="/parsing/creation-data/"></a>
<h3 class="docs-method-title" id="Creation-Data-2.11.0+"> <a href="#/parsing/creation-data/">Creation Data</a> <span>2.11.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/16-creation-data.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().creationData();
</code></pre>
</div>
<p>After a moment object is created, all of the inputs can be accessed with <code class="notranslate">creationData()</code> method:</p>

<pre class="notranslate"><code class="language-javascript">moment("2013-01-02", "YYYY-MM-DD", true).creationData() === {
    input: "2013-01-02",
    format: "YYYY-MM-DD",
    locale: Locale obj,
    isUTC: false,
    strict: true
}
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/parsing/defaults/" name="/parsing/defaults/"></a>
<h3 class="docs-method-title" id="Defaults-2.2.1+"> <a href="#/parsing/defaults/">Defaults</a> <span>2.2.1+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/01-parsing/17-defaults.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment("15", "hh")
</code></pre>
</div>
<p>You can create a moment object specifying only some of the units, and the rest will be defaulted to the current day, month or year, or 0 for hours, minutes, seconds and milliseconds.</p>
<p>Defaulting to now, when nothing is passed:</p>
<pre class="notranslate"><code class="language-javascript">moment();  // current date and time
</code></pre>
<p>Defaulting to today, when only hours, minutes, seconds and milliseconds are passed:</p>
<pre class="notranslate"><code class="language-javascript">moment(5, "HH");  // today, 5:00:00.000
moment({hour: 5});  // today, 5:00:00.000
moment({hour: 5, minute: 10});  // today, 5:10.00.000
moment({hour: 5, minute: 10, seconds: 20});  // today, 5:10.20.000
moment({hour: 5, minute: 10, seconds: 20, milliseconds: 300});  // today, 5:10.20.300
</code></pre>
<p>Defaulting to this month and year, when only days and smaller units are passed:</p>
<pre class="notranslate"><code class="language-javascript">moment(5, "DD");  // this month, 5th day-of-month
moment("4 05:06:07", "DD hh:mm:ss");  // this month, 4th day-of-month, 05:06:07.000
</code></pre>
<p>Defaulting to this year, if year is not specified:</p>
<pre class="notranslate"><code class="language-javascript">moment(3, "MM");  // this year, 3rd month (March)
moment("Apr 4 05:06:07", "MMM DD hh:mm:ss");  // this year, 4th April, 05:06:07.000
</code></pre>
</div>
</article>
<article class="docs-section">
<a class="docs-section-target" id="/get-set/" name="/get-set/"></a>
<h2 class="docs-section-title" id="Get-+-Set"><a href="#/get-set/">Get + Set</a></h2>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/intro/" name="/get-set/intro/"></a>
<div class="docs-method-prose">
<p>Moment.js uses overloaded getters and setters. You may be familiar with this pattern from its use in jQuery.</p>
<p>Calling these methods without parameters acts as a getter, and calling them with a parameter acts as a setter.</p>
<p>These map to the corresponding function on the native <code class="notranslate">Date</code> object.</p>
<pre class="notranslate"><code class="language-javascript">moment().seconds(30).valueOf() === new Date().setSeconds(30);
moment().seconds()   === new Date().getSeconds();
</code></pre>
<p>If you are in <a href="#/manipulating/utc/">UTC mode</a>, they will map to the UTC equivalent.</p>
<pre class="notranslate"><code class="language-javascript">moment.utc().seconds(30).valueOf() === new Date().setUTCSeconds(30);
moment.utc().seconds()   === new Date().getUTCSeconds();
</code></pre>
<p>For convenience, both singular and plural method names exist as of version <strong>2.0.0</strong>.</p>
<p><strong>Note:</strong> All of these methods mutate the original moment when used as setters.</p>
<p><strong>Note:</strong> From <strong>2.19.0</strong> passing <code class="notranslate">NaN</code> to any setter is a no-op. Before <strong>2.19.0</strong> it was invalidating the moment in a wrong way.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/millisecond/" name="/get-set/millisecond/"></a>
<h3 class="docs-method-title" id="Millisecond-1.3.0+"> <a href="#/get-set/millisecond/">Millisecond</a> <span>1.3.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/01-millisecond.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().millisecond(Number);
moment().millisecond(); // Number
moment().milliseconds(Number);
moment().milliseconds(); // Number
</code></pre>
</div>
<p>Gets or sets the milliseconds.</p>
<p>Accepts numbers from 0 to 999. If the range is exceeded, it will bubble up to the seconds.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/second/" name="/get-set/second/"></a>
<h3 class="docs-method-title" id="Second-1.0.0+"> <a href="#/get-set/second/">Second</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/02-second.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().second(Number);
moment().second(); // Number
moment().seconds(Number);
moment().seconds(); // Number
</code></pre>
</div>
<p>Gets or sets the seconds.</p>
<p>Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the minutes.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/minute/" name="/get-set/minute/"></a>
<h3 class="docs-method-title" id="Minute-1.0.0+"> <a href="#/get-set/minute/">Minute</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/03-minute.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().minute(Number);
moment().minute(); // Number
moment().minutes(Number);
moment().minutes(); // Number
</code></pre>
</div>
<p>Gets or sets the minutes.</p>
<p>Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the hour.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/hour/" name="/get-set/hour/"></a>
<h3 class="docs-method-title" id="Hour-1.0.0+"> <a href="#/get-set/hour/">Hour</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/04-hour.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().hour(Number);
moment().hour(); // Number
moment().hours(Number);
moment().hours(); // Number
</code></pre>
</div>
<p>Gets or sets the hour.</p>
<p>Accepts numbers from 0 to 23. If the range is exceeded, it will bubble up to the day.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/date/" name="/get-set/date/"></a>
<h3 class="docs-method-title" id="Date-of-Month-1.0.0+"> <a href="#/get-set/date/">Date of Month</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/05-date.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().date(Number);
moment().date(); // Number
moment().dates(Number);
moment().dates(); // Number
</code></pre>
</div>
<p>Gets or sets the day of the month.</p>
<p>Accepts numbers from 1 to 31. If the range is exceeded, it will bubble up to the months.</p>
<p><strong>Note:</strong> <code class="notranslate">Moment#date</code> is for the date of the month, and <code class="notranslate">Moment#day</code> is for the day of the week.</p>
<p><strong>Note:</strong> if you chain multiple actions to construct a date, you should start from a year, then a month, then a day etc. Otherwise you may get unexpected results, like when <code class="notranslate">day=31</code> and current month has only 30 days (the same applies to native JavaScript <code class="notranslate">Date</code> manipulation), the returned date will be the 30th of the current month (see <a href="javascript:window.open('http://momentjs.com/docs/#/get-set/month/');" target="_blank" rel="noopener noreferrer">month <i class="fa fa-external-link"></i></a> for more details).</p>
<p>Bad: <code class="notranslate">moment().date(day).month(month).year(year)</code></p>
<p>Good: <code class="notranslate">moment().year(year).month(month).date(day)</code></p>
<p><strong>2.16.0</strong> deprecated using <code class="notranslate">moment().dates()</code>. Use <code class="notranslate">moment().date()</code> instead.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/day/" name="/get-set/day/"></a>
<h3 class="docs-method-title" id="Day-of-Week-1.3.0+"> <a href="#/get-set/day/">Day of Week</a> <span>1.3.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/06-day.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().day(Number|String);
moment().day(); // Number
moment().days(Number|String);
moment().days(); // Number
</code></pre>
</div>
<p>Gets or sets the day of the week.</p>
<p>This method can be used to set the day of the week, with Sunday as 0 and Saturday as 6.</p>
<p>If the value given is from 0 to 6, the resulting date will be within the current (Sunday-to-Saturday) week.</p>
<p>If the range is exceeded, it will bubble up to other weeks.</p>
<pre class="notranslate"><code class="language-javascript">moment().day(-7); // last Sunday (0 - 7)
moment().day(0); // this Sunday (0)
moment().day(7); // next Sunday (0 + 7)
moment().day(10); // next Wednesday (3 + 7)
moment().day(24); // 3 Wednesdays from now (3 + 7 + 7 + 7)
</code></pre>
<p><strong>Note:</strong> <code class="notranslate">Moment#date</code> is for the date of the month, and <code class="notranslate">Moment#day</code> is for the day of the week.</p>
<p>As of <strong>2.1.0</strong>, a day name is also supported. This is parsed in the moment's current locale.</p>
<pre class="notranslate"><code class="language-javascript">moment().day("Sunday");
moment().day("Monday");
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/weekday/" name="/get-set/weekday/"></a>
<h3 class="docs-method-title" id="Day-of-Week-(Locale-Aware)-2.1.0+"> <a href="#/get-set/weekday/">Day of Week (Locale Aware)</a> <span>2.1.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/07-weekday.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().weekday(Number);
moment().weekday(); // Number
</code></pre>
</div>
<p>Gets or sets the day of the week according to the locale.</p>
<p>If the locale assigns Monday as the first day of the week, <code class="notranslate">moment().weekday(0)</code> will be Monday. If Sunday is the first day of the week, <code class="notranslate">moment().weekday(0)</code> will be Sunday.</p>
<p>As with <code class="notranslate">moment#day</code>, if the range is exceeded, it will bubble up to other weeks.</p>
<pre class="notranslate"><code class="language-javascript">// when Monday is the first day of the week
moment().weekday(-7); // last Monday
moment().weekday(7); // next Monday
// when Sunday is the first day of the week
moment().weekday(-7); // last Sunday
moment().weekday(7); // next Sunday
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/iso-weekday/" name="/get-set/iso-weekday/"></a>
<h3 class="docs-method-title" id="ISO-Day-of-Week-2.1.0+"> <a href="#/get-set/iso-weekday/">ISO Day of Week</a> <span>2.1.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/08-iso-weekday.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isoWeekday(Number);
moment().isoWeekday(); // Number
</code></pre>
</div>
<p>Gets or sets the <a href="javascript:window.open('https://en.wikipedia.org/wiki/ISO_week_date');" target="_blank" rel="noopener noreferrer">ISO day of the week <i class="fa fa-external-link"></i></a> with <code class="notranslate">1</code> being Monday and <code class="notranslate">7</code> being Sunday.</p>
<p>As with <code class="notranslate">moment#day</code>, if the range is exceeded, it will bubble up to other weeks.</p>
<pre class="notranslate"><code class="language-javascript">moment().isoWeekday(1); // Monday
moment().isoWeekday(7); // Sunday
</code></pre>
<p>A day name is also supported. This is parsed in the moment's current locale.</p>
<pre class="notranslate"><code class="language-javascript">moment().isoWeekday("Sunday");
moment().isoWeekday("Monday");
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/day-of-year/" name="/get-set/day-of-year/"></a>
<h3 class="docs-method-title" id="Day-of-Year-2.0.0+"> <a href="#/get-set/day-of-year/">Day of Year</a> <span>2.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/09-day-of-year.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().dayOfYear(Number);
moment().dayOfYear(); // Number
</code></pre>
</div>
<p>Gets or sets the day of the year.</p>
<p>Accepts numbers from 1 to 366. If the range is exceeded, it will bubble up to the years.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/week/" name="/get-set/week/"></a> 
<h3 class="docs-method-title" id="Week-of-Year-2.0.0+"> <a href="#/get-set/week/">Week of Year</a> <span>2.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/10-week.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().week(Number);
moment().week(); // Number
moment().weeks(Number);
moment().weeks(); // Number
</code></pre>
</div>
<p>Gets or sets the week of the year.</p>
<p>Because different locales define week of year numbering differently, Moment.js added <code class="notranslate">moment#week</code> to get/set the localized week of the year.</p>
<p>The week of the year varies depending on which day is the first day of the week (Sunday, Monday, etc), and which week is the first week of the year.</p>
<p>For example, in the United States, Sunday is the first day of the week. The week with January 1st in it is the first week of the year.</p>
<p>In France, Monday is the first day of the week, and the week with January 4th is the first week of the year.</p>
<p>The output of <code class="notranslate">moment#week</code> will depend on the <a href="#/i18n">locale</a> for that moment.</p>
<p>When setting the week of the year, the day of the week is retained.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/iso-week/" name="/get-set/iso-week/"></a>
<h3 class="docs-method-title" id="Week-of-Year-(ISO)-2.0.0+"> <a href="#/get-set/iso-week/">Week of Year (ISO)</a> <span>2.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/11-iso-week.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isoWeek(Number);
moment().isoWeek(); // Number
moment().isoWeeks(Number);
moment().isoWeeks(); // Number
</code></pre>
</div>
<p>Gets or sets the <a href="javascript:window.open('https://en.wikipedia.org/wiki/ISO_week_date');" target="_blank" rel="noopener noreferrer">ISO week of the year <i class="fa fa-external-link"></i></a>.</p>
<p>When setting the week of the year, the day of the week is retained.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/month/" name="/get-set/month/"></a>
<h3 class="docs-method-title" id="Month-1.0.0+"> <a href="#/get-set/month/">Month</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/12-month.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().month(Number|String);
moment().month(); // Number
moment().months(Number|String);
moment().months(); // Number
</code></pre>
</div>
<p>Gets or sets the month.</p>
<p>Accepts numbers from 0 to 11. If the range is exceeded, it will bubble up to the year.</p>
<p><strong>Note:</strong> Months are zero indexed, so January is month 0.</p>
<p>As of <strong>2.1.0</strong>, a month name is also supported. This is parsed in the moment's current locale.</p>
<pre class="notranslate"><code class="language-javascript">moment().month("January");
moment().month("Feb");
</code></pre>
<p>Before version <strong>2.1.0</strong>, if a moment changed months and the new month did not have enough days to keep the current day of month, it would overflow to the next month.</p>
<p>As of version <strong>2.1.0</strong>, this was changed to be clamped to the end of the target month.</p>
<pre class="notranslate"><code class="language-javascript">// before 2.1.0
moment([2012, 0, 31]).month(1).format("YYYY-MM-DD"); // 2012-03-02
// after 2.1.0
moment([2012, 0, 31]).month(1).format("YYYY-MM-DD"); // 2012-02-29
</code></pre>
<p><strong>2.16.0</strong> deprecated using <code class="notranslate">moment().months()</code>. Use <code class="notranslate">moment().month()</code> instead.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/quarter/" name="/get-set/quarter/"></a>
<h3 class="docs-method-title" id="Quarter-2.6.0+"> <a href="#/get-set/quarter/">Quarter</a> <span>2.6.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/13-quarter.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().quarter(); // Number
moment().quarter(Number);
moment().quarters(); // Number
moment().quarters(Number);
</code></pre>
</div>
<p>Gets the quarter (1 to 4).</p>
<pre class="notranslate"><code class="language-javascript">moment('2013-01-01T00:00:00.000').quarter() // 1
moment('2013-04-01T00:00:00.000').subtract(1, 'ms').quarter() // 1
moment('2013-04-01T00:00:00.000').quarter() // 2
moment('2013-07-01T00:00:00.000').subtract(1, 'ms').quarter() // 2
moment('2013-07-01T00:00:00.000').quarter() // 3
moment('2013-10-01T00:00:00.000').subtract(1, 'ms').quarter() // 3
moment('2013-10-01T00:00:00.000').quarter() // 4
moment('2014-01-01T00:00:00.000').subtract(1, 'ms').quarter() // 4
</code></pre>
<p>Sets the quarter (1 to 4).</p>
<pre class="notranslate"><code class="language-javascript">moment('2013-01-01T00:00:00.000').quarter(2) // '2013-04-01T00:00:00.000'
moment('2013-02-05T05:06:07.000').quarter(2).format() // '2013-05-05T05:06:07-07:00'
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/year/" name="/get-set/year/"></a>
<h3 class="docs-method-title" id="Year-1.0.0+"> <a href="#/get-set/year/">Year</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/14-year.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().year(Number);
moment().year(); // Number
moment().years(Number);
moment().years(); // Number
</code></pre>
</div>
<p>Gets or sets the year.</p>
<p>Accepts numbers from -270,000 to 270,000.</p>
<p><strong>2.6.0</strong> deprecated using <code class="notranslate">moment().years()</code>. Use <code class="notranslate">moment().year()</code> instead.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/week-year/" name="/get-set/week-year/"></a>
<h3 class="docs-method-title" id="Week-Year-2.1.0+"> <a href="#/get-set/week-year/">Week Year</a> <span>2.1.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/15-week-year.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().weekYear(Number);
moment().weekYear(); // Number
</code></pre>
</div>
<p>Gets or sets the week-year according to the locale.</p>
<p>Because the first day of the first week does not always fall on the first day of the year, sometimes the week-year will differ from the month year.</p>
<p>For example, in the US, the week that contains Jan 1 is always the first week. In the US, weeks also start on Sunday. If Jan 1 was a Monday, Dec 31 would belong to the same week as Jan 1, and thus the same week-year as Jan 1. Dec 30 would have a different week-year than Dec 31.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/iso-week-year/" name="/get-set/iso-week-year/"></a>
<h3 class="docs-method-title" id="Week-Year-(ISO)-2.1.0+"> <a href="#/get-set/iso-week-year/">Week Year (ISO)</a> <span>2.1.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/16-iso-week-year.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isoWeekYear(Number);
moment().isoWeekYear(); // Number
</code></pre>
</div>
<p>Gets or sets the <a href="javascript:window.open('https://en.wikipedia.org/wiki/ISO_week_date');" target="_blank" rel="noopener noreferrer">ISO week-year <i class="fa fa-external-link"></i></a>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/weeks-in-year/" name="/get-set/weeks-in-year/"></a>
<h3 class="docs-method-title" id="Weeks-In-Year-2.6.0+"> <a href="#/get-set/weeks-in-year/">Weeks In Year</a> <span>2.6.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/17-weeks-in-year.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().weeksInYear();
</code></pre>
</div>
<p>Gets the number of weeks according to locale in the current moment's year.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/iso-weeks-in-year/" name="/get-set/iso-weeks-in-year/"></a>
<h3 class="docs-method-title" id="Weeks-In-Year-(ISO)-2.6.0+"> <a href="#/get-set/iso-weeks-in-year/">Weeks In Year (ISO)</a> <span>2.6.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/18-iso-weeks-in-year.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isoWeeksInYear();
</code></pre>
</div>
<p>Gets the number of weeks in the current moment's year, according to <a href="javascript:window.open('https://en.wikipedia.org/wiki/ISO_week_date');" target="_blank" rel="noopener noreferrer">ISO weeks <i class="fa fa-external-link"></i></a>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/get/" name="/get-set/get/"></a>
<h3 class="docs-method-title" id="Get-2.2.1+"> <a href="#/get-set/get/">Get</a> <span>2.2.1+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/19-get.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().get('year');
moment().get('month');  // 0 to 11
moment().get('date');
moment().get('hour');
moment().get('minute');
moment().get('second');
moment().get('millisecond');
</code></pre>
</div>
<p>String getter. In general</p>
<pre class="notranslate"><code class="language-javascript">moment().get(unit) === moment()[unit]()
</code></pre>
<p>Units are case insensitive, and support plural and short forms: year (years, y), month (months, M), date (dates, D), hour (hours, h), minute (minutes, m), second (seconds, s), millisecond (milliseconds, ms).</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/set/" name="/get-set/set/"></a>
<h3 class="docs-method-title" id="Set-2.2.1+"> <a href="#/get-set/set/">Set</a> <span>2.2.1+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/20-set.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().set(String, Int);
moment().set(Object(String, Int));
</code></pre>
</div>
<p>Generic setter, accepting unit as first argument, and value as second:</p>
<pre class="notranslate"><code class="language-javascript">moment().set('year', 2013);
moment().set('month', 3);  // April
moment().set('date', 1);
moment().set('hour', 13);
moment().set('minute', 20);
moment().set('second', 30);
moment().set('millisecond', 123);

moment().set({'year': 2013, 'month': 3});
</code></pre>
<p>Units are case insensitive, and support plural and short forms: year (years, y), month (months, M), date (dates, D), hour (hours, h), minute (minutes, m), second (seconds, s), millisecond (milliseconds, ms).</p>
<p>Object parsing was added in <strong>2.9.0</strong></p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/max/" name="/get-set/max/"></a>
<h3 class="docs-method-title" id="Maximum-2.7.0+"> <a href="#/get-set/max/">Maximum</a> <span>2.7.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/21-max.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment.max(Moment[,Moment...]);
moment.max(Moment[]);
</code></pre>
</div>
<p>Returns the maximum (most distant future) of the given moment instances.</p>
<p>For example:</p>
<pre class="notranslate"><code class="language-javascript">var a = moment().subtract(1, 'day');
var b = moment().add(1, 'day');
moment.max(a, b);  // b

var friends = fetchFriends(); /* [{name: 'Dan', birthday: '11.12.1977'}, {name: 'Mary', birthday: '11.12.1986'}, {name: 'Stephan', birthday: '11.01.1993'}]*/
var friendsBirthDays = friends.map(function(friend){
    return moment(friend.birthday, 'DD.MM.YYYY');
});
moment.max(friendsBirthDays);  // '11.01.1993'
</code></pre>
<p>With no arguments the function returns a moment instance with the current time.</p>
<p>From version <strong>2.10.5</strong>, if an invalid moment is one of the arguments, the result is an invalid moment.</p>
<pre class="notranslate"><code class="language-javascript">moment.max(moment(), moment.invalid()).isValid() === false
moment.max(moment.invalid(), moment()).isValid() === false
moment.max([moment(), moment.invalid()]).isValid() === false
moment.max([moment.invalid(), moment()]).isValid() === false
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/get-set/min/" name="/get-set/min/"></a>
<h3 class="docs-method-title" id="Minimum-2.7.0+"> <a href="#/get-set/min/">Minimum</a> <span>2.7.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/02-get-set/22-min.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment.min(Moment[,Moment...]);
moment.min(Moment[]);
</code></pre>
</div>
<p>Returns the minimum (most distant past) of the given moment instances.</p>
<p>For example:</p>
<pre class="notranslate"><code class="language-javascript">var a = moment().subtract(1, 'day');
var b = moment().add(1, 'day');
moment.min(a, b);  // a
moment.min([a, b]); // a
</code></pre>
<p>With no arguments the function returns a moment instance with the current time.</p>
<p>From version <strong>2.10.5</strong>, if an invalid moment is one of the arguments, the result is an invalid moment.</p>
<pre class="notranslate"><code class="language-javascript">moment.min(moment(), moment.invalid()).isValid() === false
moment.min(moment.invalid(), moment()).isValid() === false
moment.min([moment(), moment.invalid()]).isValid() === false
moment.min([moment.invalid(), moment()]).isValid() === false
</code></pre>
</div>
</article>
<article class="docs-section">
<a class="docs-section-target" id="/manipulating/" name="/manipulating/"></a>
<h2 class="docs-section-title" id="Manipulate"><a href="#/manipulating/">Manipulate</a></h2>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/intro/" name="/manipulating/intro/"></a>
<div class="docs-method-prose">
<p>Once you have a <code class="notranslate">Moment</code>, you may want to manipulate it in some way. There are a number of methods to help with this.</p>
<p>Moment.js uses the <a href="javascript:window.open('https://en.wikipedia.org/wiki/Fluent_interface');" target="_blank" rel="noopener noreferrer">fluent interface pattern <i class="fa fa-external-link"></i></a>, also known as <a href="javascript:window.open('https://en.wikipedia.org/wiki/Method_chaining');" target="_blank" rel="noopener noreferrer">method chaining <i class="fa fa-external-link"></i></a>. This allows you to do crazy things like the following.</p>
<pre class="notranslate"><code class="language-javascript">moment().add(7, 'days').subtract(1, 'months').year(2009).hours(0).minutes(0).seconds(0);
</code></pre>
<p><strong>Note:</strong> It should be noted that moments are mutable. Calling any of the manipulation methods will change the original moment.</p>
<p>If you want to create a copy and manipulate it, you should use <code class="notranslate">moment#clone</code> before manipulating the moment. <a href="#/parsing/moment-clone/">More info on cloning.</a></p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/add/" name="/manipulating/add/"></a>
<h3 class="docs-method-title" id="Add-1.0.0+"> <a href="#/manipulating/add/">Add</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/01-add.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().add(Number, String);
moment().add(Duration);
moment().add(Object);
</code></pre>
</div>
<p>Mutates the original moment by adding time.</p>
<p>This is a pretty robust function for adding time to an existing moment. To add time, pass the key of what time you want to add, and the amount you want to add.</p>
<pre class="notranslate"><code class="language-javascript">moment().add(7, 'days');
</code></pre>
<p>There are some shorthand keys as well if you're into that whole brevity thing.</p>
<pre class="notranslate"><code class="language-javascript">moment().add(7, 'd');
</code></pre>
<table class="table table-striped table-bordered">
<tbody>
<tr>
<th>Key</th>
<th>Shorthand</th>
</tr>
<tr>
<td>years</td>
<td>y</td>
</tr>
<tr>
<td>quarters</td>
<td>Q</td>
</tr>
<tr>
<td>months</td>
<td>M</td>
</tr>
<tr>
<td>weeks</td>
<td>w</td>
</tr>
<tr>
<td>days</td>
<td>d</td>
</tr>
<tr>
<td>hours</td>
<td>h</td>
</tr>
<tr>
<td>minutes</td>
<td>m</td>
</tr>
<tr>
<td>seconds</td>
<td>s</td>
</tr>
<tr>
<td>milliseconds</td>
<td>ms</td>
</tr>
</tbody>
</table>
<p>If you want to add multiple different keys at the same time, you can pass them in as an object literal.</p>
<pre class="notranslate"><code class="language-javascript">moment().add(7, 'days').add(1, 'months'); // with chaining
moment().add({days:7,months:1}); // with object literal
</code></pre>
<p>There are no upper limits for the amounts, so you can overload any of the parameters.</p>
<pre class="notranslate"><code class="language-javascript">moment().add(1000000, 'milliseconds'); // a million milliseconds
moment().add(360, 'days'); // 360 days
</code></pre>
<h4 id="Special-considerations-for-months-and-years">Special considerations for months and years</h4>
<p>If the day of the month on the original date is greater than the number of days in the final month, the day of the month will change to the last day in the final month.</p>
<pre class="notranslate"><code class="language-javascript">moment([2010, 0, 31]);                  // January 31
moment([2010, 0, 31]).add(1, 'months'); // February 28
</code></pre>
<p>There are also special considerations to keep in mind when adding time that crosses over daylight saving time. If you are adding years, months, weeks, or days, the original hour will always match the added hour.</p>
<p>Adding a month will add the specified number of months to the date.</p>
<pre class="notranslate"><code class="language-javascript">moment([2010, 1, 28]);                 // February 28
moment([2010, 1, 28]).add(1, 'month'); // March 28
</code></pre>
<pre class="notranslate"><code class="language-javascript">var m = moment(new Date(2011, 2, 12, 5, 0, 0)); // the day before DST in the US
m.hours(); // 5
m.add(1, 'days').hours(); // 5
</code></pre>
<p>If you are adding hours, minutes, seconds, or milliseconds, the assumption is that you want precision to the hour, and will result in a different hour.</p>
<pre class="notranslate"><code class="language-javascript">var m = moment(new Date(2011, 2, 12, 5, 0, 0)); // the day before DST in the US
m.hours(); // 5
m.add(24, 'hours').hours(); // 6 (but you may have to set the timezone first)
</code></pre>
<p>Alternatively, you can use <a href="#/durations/">durations</a> to add to moments.</p>
<pre class="notranslate"><code class="language-javascript">var duration = moment.duration({'days' : 1});
moment([2012, 0, 31]).add(duration); // February 1
</code></pre>
<p>Before version <strong>2.8.0</strong>, the <code class="notranslate">moment#add(String, Number)</code> syntax was also supported. It has been deprecated in favor of <code class="notranslate">moment#add(Number, String)</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment().add('seconds', 1); // Deprecated in 2.8.0
moment().add(1, 'seconds');
</code></pre>
<p>As of <strong>2.12.0</strong> when decimal values are passed for days and months, they are rounded to the nearest integer. Weeks, quarters, and years are converted to days or months, and then rounded to the nearest integer.</p>
<pre class="notranslate"><code class="language-javascript">moment().add(1.5, 'months') == moment().add(2, 'months')
moment().add(.7, 'years') == moment().add(8, 'months') //.7*12 = 8.4, rounded to 8
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/subtract/" name="/manipulating/subtract/"></a>
<h3 class="docs-method-title" id="Subtract-1.0.0+"> <a href="#/manipulating/subtract/">Subtract</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/02-subtract.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().subtract(Number, String);
moment().subtract(Duration);
moment().subtract(Object);
</code></pre>
</div>
<p>Mutates the original moment by subtracting time.</p>
<p>This is exactly the same as <code class="notranslate">moment#add</code>, only instead of adding time, it subtracts time.</p>
<pre class="notranslate"><code class="language-javascript">moment().subtract(7, 'days');
</code></pre>
<p>Before version <strong>2.8.0</strong>, the <code class="notranslate">moment#subtract(String, Number)</code> syntax was also supported. It has been deprecated in favor of <code class="notranslate">moment#subtract(Number, String)</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment().subtract('seconds', 1); // Deprecated in 2.8.0
moment().subtract(1, 'seconds');
</code></pre> 
<p>As of <strong>2.12.0</strong> when decimal values are passed for days and months, they are rounded to the nearest integer. Weeks, quarters, and years are converted to days or months, and then rounded to the nearest integer.</p>
<pre class="notranslate"><code class="language-javascript">moment().subtract(1.5, 'months') == moment().subtract(2, 'months')
moment().subtract(.7, 'years') == moment().subtract(8, 'months') //.7*12 = 8.4, rounded to 8
</code></pre>
<p>Note that in order to make the operations <code class="notranslate">moment.add(-.5, 'days')</code> and <code class="notranslate">moment.subtract(.5, 'days')</code> equivalent, -.5, -1.5, -2.5, etc are rounded down.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/start-of/" name="/manipulating/start-of/"></a>
<h3 class="docs-method-title" id="Start-of-Time-1.7.0+"> <a href="#/manipulating/start-of/">Start of Time</a> <span>1.7.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/03-start-of.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().startOf(String);
</code></pre>
</div>
<p>Mutates the original moment by setting it to the start of a unit of time.</p>
<pre class="notranslate"><code class="language-javascript">moment().startOf('year');    // set to January 1st, 12:00 am this year
moment().startOf('month');   // set to the first of this month, 12:00 am
moment().startOf('quarter');  // set to the beginning of the current quarter, 1st day of months, 12:00 am
moment().startOf('week');    // set to the first day of this week, 12:00 am
moment().startOf('isoWeek'); // set to the first day of this week according to ISO 8601, 12:00 am
moment().startOf('day');     // set to 12:00 am today
moment().startOf('date');     // set to 12:00 am today
moment().startOf('hour');    // set to now, but with 0 mins, 0 secs, and 0 ms
moment().startOf('minute');  // set to now, but with 0 seconds and 0 milliseconds
moment().startOf('second');  // same as moment().milliseconds(0);
</code></pre>
<p>These shortcuts are essentially the same as the following.</p>
<pre class="notranslate"><code class="language-javascript">moment().startOf('year');
moment().month(0).date(1).hours(0).minutes(0).seconds(0).milliseconds(0);
</code></pre>
<pre class="notranslate"><code class="language-javascript">moment().startOf('hour');
moment().minutes(0).seconds(0).milliseconds(0)
</code></pre>
<p>As of version <strong>2.0.0</strong>, <code class="notranslate">moment#startOf('day')</code> replaced <code class="notranslate">moment#sod</code>.</p>
<p><strong>Note:</strong> <code class="notranslate">moment#startOf('week')</code> was added in version <strong>2.0.0</strong>.</p>
<p>As of version <strong>2.1.0</strong>, <code class="notranslate">moment#startOf('week')</code> uses the locale aware week start day.</p>
<p><strong>Note:</strong> <code class="notranslate">moment#startOf('isoWeek')</code> was added in version <strong>2.2.0</strong>.</p>
<p><strong>Note:</strong> <code class="notranslate">moment#startOf('date')</code> was added as an alias for day in <strong>2.13.0</strong></p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/end-of/" name="/manipulating/end-of/"></a>
<h3 class="docs-method-title" id="End-of-Time-1.7.0+"> <a href="#/manipulating/end-of/">End of Time</a> <span>1.7.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/04-end-of.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().endOf(String);
</code></pre>
</div>
<p>Mutates the original moment by setting it to the end of a unit of time.</p>
<p>This is the same as <code class="notranslate">moment#startOf</code>, only instead of setting to the start of a unit of time, it sets to the end of a unit of time.</p>
<pre class="notranslate"><code class="language-javascript">moment().endOf("year"); // set the moment to 12-31 23:59:59.999 this year
</code></pre>
<p>As of version <strong>2.0.0</strong>, <code class="notranslate">moment#endOf('day')</code> replaced <code class="notranslate">moment#eod</code>.</p>
<p><strong>Note:</strong> <code class="notranslate">moment#endOf('week')</code> was added in version <strong>2.0.0</strong>.</p>
<p>As of version <strong>2.1.0</strong>, <code class="notranslate">moment#endOf('week')</code> uses the locale aware week start day.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/max/" name="/manipulating/max/"></a>
<h3 class="docs-method-title" id="Maximum-From-2.1.0,-Deprecated-2.7.0"> <a href="#/manipulating/max/">Maximum</a> <span>From 2.1.0, Deprecated 2.7.0</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/05-max.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().max(Moment|String|Number|Date|Array);
</code></pre>
</div>
<p><strong>Note:</strong> This function has been <strong>deprecated</strong> in <strong>2.7.0</strong>. Consider <a href="#/get-set/min/"><code class="notranslate">moment.min</code></a> instead.</p>
<hr>
<p>Limits the moment to a maximum of another moment value. So <code class="notranslate">a.max(b)</code> is the same as <code class="notranslate">a = moment.min(a, b)</code> (note that <code class="notranslate">max</code> is converted to <code class="notranslate">min</code>).</p>
<p>Sometimes, server clocks are not quite in sync with client clocks. This ends up displaying humanized strings such as "in a few seconds" rather than "a few seconds ago". You can prevent that with <code class="notranslate">moment#max()</code>:</p>
<p>This is the counterpart for <code class="notranslate">moment#min</code>.</p>
<pre class="notranslate"><code class="language-javascript">var momentFromServer = moment(input);
var clampedMoment = momentFromServer.max();
</code></pre>
<p>You can pass anything to <code class="notranslate">moment#max</code> that you would pass to <code class="notranslate">moment()</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment().max(moment().add(1, 'd'));
moment().max("2013-04-20T20:00:00+0800");
moment().max("Jan 1 2001", "MMM D YYYY");
moment().max(new Date(2012, 1, 8));
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/min/" name="/manipulating/min/"></a>
<h3 class="docs-method-title" id="Minimum-From-2.1.0,-Deprecated-2.7.0"> <a href="#/manipulating/min/">Minimum</a> <span>From 2.1.0, Deprecated 2.7.0</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/06-min.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().min(Moment|String|Number|Date|Array);
</code></pre>
</div>
<p><strong>Note:</strong> This function has been <strong>deprecated</strong> in <strong>2.7.0</strong>. Consider <a href="#/get-set/max/"><code class="notranslate">moment.max</code></a> instead.</p>
<hr>
<p>Limits the moment to a minimum of another moment value. So <code class="notranslate">a.min(b)</code> is the same as <code class="notranslate">a = moment.max(a, b)</code> (note that <code class="notranslate">min</code> is converted to <code class="notranslate">max</code>).</p>
<p>This is the counterpart for <code class="notranslate">moment#max</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment().min("2013-04-20T20:00:00+0800");
</code></pre>
<p>This can be used in conjunction with <code class="notranslate">moment#max</code> to clamp a moment to a range.</p>
<pre class="notranslate"><code class="language-javascript">var start  = moment().startOf('week');
var end    = moment().endOf('week');
var actual = moment().min(start).max(end);
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/local/" name="/manipulating/local/"></a>
<h3 class="docs-method-title" id="Local-1.5.0+"> <a href="#/manipulating/local/">Local</a> <span>1.5.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/07-local.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().local();
</code></pre>
</div>
<p>Sets a flag on the original moment to use local time to display a moment instead of the original moment's time.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment.utc([2011, 0, 1, 8]);
a.hours(); // 8 UTC
a.local();
a.hours(); // 0 PST
</code></pre>
<p>Local can also be used to convert out of a fixed offset mode:</p>
<pre class="notranslate"><code class="language-javascript">moment.parseZone('2016-05-03T22:15:01+02:00').local().format(); // "2016-05-03T15:15:01-05:00"
</code></pre>
<p>See <a href="#/parsing/utc/">moment.utc()</a> for more information on UTC mode.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/utc/" name="/manipulating/utc/"></a>
<h3 class="docs-method-title" id="UTC-1.5.0+"> <a href="#/manipulating/utc/">UTC</a> <span>1.5.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/08-utc.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().utc();
</code></pre>
</div>
<p>Sets a flag on the original moment to use UTC to display a moment instead of the original moment's time.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2011, 0, 1, 8]);
a.hours(); // 8 PST
a.utc();
a.hours(); // 16 UTC
</code></pre>
<p>UTC can also be used to convert out of a fixed offset mode:</p>
<pre class="notranslate"><code class="language-javascript">moment.parseZone('2016-05-03T22:15:01+02:00').utc().format(); //"2016-05-03T20:15:01Z"
</code></pre>
<p>See <a href="#/parsing/utc/">moment.utc()</a> for more information on UTC mode.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/utc-offset/" name="/manipulating/utc-offset/"></a>
<h3 class="docs-method-title" id="UTC-offset-2.9.0++"> <a href="#/manipulating/utc-offset/">UTC offset</a> <span>2.9.0++</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/09-utc-offset.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().utcOffset();
moment().utcOffset(Number|String);
moment().utcOffset(Number|String, Boolean);
</code></pre>
</div>
<p>Get or set the UTC offset in minutes.</p>
<p><strong>Note:</strong> Unlike <a href="#/manipulating/timezone-offset/"><code class="notranslate">moment.fn.zone</code></a> this function returns the real offset from UTC, not the reverse offset (as returned by <code class="notranslate">Date.prototype.getTimezoneOffset</code>).</p>
<p>Getting the <code class="notranslate">utcOffset</code> of the current object:</p>
<pre class="notranslate"><code class="language-javascript">moment().utcOffset(); // (-240, -120, -60, 0, 60, 120, 240, etc.)
</code></pre>
<p>Setting the UTC offset by supplying minutes. The offset is set on the moment object that <code class="notranslate">utcOffset()</code> is called on. If you are wanting to set the offset globally, try using <a href="javascript:window.open('https://momentjs.com/timezone/');" target="_blank" rel="noopener noreferrer">moment-timezone <i class="fa fa-external-link"></i></a>. Note that once you set an offset, it's fixed and won't change on its own (i.e there are no DST rules). If you want an actual time zone -- time in a particular location, like <code class="notranslate">America/Los_Angeles</code>, consider <a href="javascript:window.open('https://momentjs.com/timezone/');" target="_blank" rel="noopener noreferrer">moment-timezone <i class="fa fa-external-link"></i></a>.</p>
<pre class="notranslate"><code class="language-javascript">moment().utcOffset(120);
</code></pre>
<p>If the input is less than <code class="notranslate">16</code> and greater than <code class="notranslate">-16</code>, it will interpret your input as hours instead.</p>
<pre class="notranslate"><code class="language-javascript">// these are equivalent
moment().utcOffset(8);  // set hours offset
moment().utcOffset(480);  // set minutes offset (8 * 60)
</code></pre>
<p>It is also possible to set the UTC offset from a string.</p>
<pre class="notranslate"><code class="language-javascript">// these are equivalent
moment().utcOffset("+08:00");
moment().utcOffset(8);
moment().utcOffset(480);
</code></pre>
<p><code class="notranslate">moment#utcOffset</code> will search the string for the first match of <code class="notranslate">+00:00 +0000 -00:00 -0000 Z</code>, so you can even pass an ISO8601 formatted string and the moment will be changed to that UTC offset.</p>
<p>Note that the string, if not 'Z', is required to start with the <code class="notranslate">+</code> or <code class="notranslate">-</code> character.</p>
<pre class="notranslate"><code class="language-javascript">moment().utcOffset("2013-03-07T07:00:00+08:00");
</code></pre>
<p>The <code class="notranslate">utcOffset</code> function has an optional second parameter which accepts a boolean value indicating whether to keep the existing time of day.</p>
<ul>
<li><p>Passing <code class="notranslate">false</code> (the default) will keep the same instant in Universal Time, but the local time will change.</p></li>
<li><p>Passing <code class="notranslate">true</code> will keep the same local time, but at the expense of choosing a different point in Universal Time.</p></li>
</ul>
<p>One use of this feature is if you want to construct a moment with a specific time zone offset using only numeric input values:</p>
<pre class="notranslate"><code class="language-javascript">moment([2016, 0, 1, 0, 0, 0]).utcOffset(-5, true) // Equivalent to "2016-01-01T00:00:00-05:00"
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/manipulating/timezone-offset/" name="/manipulating/timezone-offset/"></a>
<h3 class="docs-method-title" id="Time-zone-Offset-From-1.2.0,-deprecated-2.9.0+"> <a href="#/manipulating/timezone-offset/">Time zone Offset</a> <span>From 1.2.0, deprecated 2.9.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/03-manipulating/10-timezone-offset.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().zone();
moment().zone(Number|String);
</code></pre>
</div>
<p><strong>Note:</strong> This function has been <strong>deprecated</strong> in <strong>2.9.0</strong>. Consider <a href="#/manipulating/utc-offset/"><code class="notranslate">moment.fn.utcOffset</code></a> instead.</p>
<p>Get the time zone offset in minutes.</p>
<pre class="notranslate"><code class="language-javascript">moment().zone(); // (60, 120, 240, etc.)
</code></pre>
<p>As of version <strong>2.1.0</strong>, it is possible to set the offset by passing in the number of minutes offset from GMT.</p>
<pre class="notranslate"><code class="language-javascript">moment().zone(120);
</code></pre>
<p>If the input is less than <code class="notranslate">16</code> and greater than <code class="notranslate">-16</code>, it will interpret your input as hours instead.</p>
<pre class="notranslate"><code class="language-javascript">// these are equivalent
moment().zone(480);
moment().zone(8);
</code></pre>
<p>It is also possible to set the zone from a string.</p>
<pre class="notranslate"><code class="language-javascript">moment().zone("-08:00");
</code></pre>
<p><code class="notranslate">moment#zone</code> will search the string for the first match of <code class="notranslate">+00:00 +0000 -00:00 -0000</code>, so you can even pass an ISO8601 formatted string and the moment will be changed to that zone.</p>
<pre class="notranslate"><code class="language-javascript">moment().zone("2013-03-07T07:00:00-08:00");
</code></pre>
</div>
</article>
<article class="docs-section">
<a class="docs-section-target" id="/displaying/" name="/displaying/"></a>
<h2 class="docs-section-title" id="Display"><a href="#/displaying/">Display</a></h2>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/intro/" name="/displaying/intro/"></a>
<div class="docs-method-prose">
<p>Once parsing and manipulation are done, you need some way to display the moment.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/format/" name="/displaying/format/"></a>
<h3 class="docs-method-title" id="Format-1.0.0+"> <a href="#/displaying/format/">Format</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/01-format.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().format();
moment().format(String);
</code></pre>
</div>
<p>This is the most robust display option. It takes a string of tokens and replaces them with their corresponding values.</p>
<pre class="notranslate"><code class="language-javascript">moment().format();                                // "2014-09-08T08:02:17-05:00" (ISO 8601, no fractional seconds)
moment().format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Sunday, February 14th 2010, 3:25:50 pm"
moment().format("ddd, hA");                       // "Sun, 3PM"
moment().format("[Today is] dddd");               // "Today is Sunday"
moment('gibberish').format('YYYY MM DD');         // "Invalid date"
</code></pre>
<table class="table table-striped table-bordered">
<tbody>
<tr>
<th></th>
<th>Token</th>
<th>Output</th>
</tr>
<tr>
<td><b class="notranslate">Month</b></td>
<td>M</td>
<td>1 2 ... 11 12</td>
</tr>
<tr>
<td></td>
<td>Mo</td>
<td>1st 2nd ... 11th 12th</td>
</tr>
<tr>
<td></td>
<td>MM</td>
<td>01 02 ... 11 12</td>
</tr>
<tr>
<td></td>
<td>MMM</td>
<td>Jan Feb ... Nov Dec</td>
</tr>
<tr>
<td></td>
<td>MMMM</td>
<td>January February ... November December</td>
</tr>
<tr>
<td><b class="notranslate">Quarter</b></td>
<td>Q</td>
<td>1 2 3 4</td>
</tr>
<tr>
<td></td>
<td>Qo</td>
<td>1st 2nd 3rd 4th</td>
</tr>
<tr>
<td><b class="notranslate">Day of Month</b></td>
<td>D</td>
<td>1 2 ... 30 31</td>
</tr>
<tr>
<td></td>
<td>Do</td>
<td>1st 2nd ... 30th 31st</td>
</tr>
<tr>
<td></td>
<td>DD</td>
 <td>01 02 ... 30 31</td>
</tr>
<tr>
<td><b class="notranslate">Day of Year</b></td>
<td>DDD</td>
<td>1 2 ... 364 365</td>
</tr>
<tr>
<td></td>
<td>DDDo</td>
<td>1st 2nd ... 364th 365th</td>
</tr>
<tr>
<td></td>
<td>DDDD</td>
<td>001 002 ... 364 365</td>
</tr>
<tr>
<td><b class="notranslate">Day of Week</b></td>
<td>d</td>
<td>0 1 ... 5 6</td>
</tr>
<tr>
<td></td>
<td>do</td>
<td>0th 1st ... 5th 6th</td>
</tr>
<tr>
<td></td>
<td>dd</td>
<td>Su Mo ... Fr Sa</td>
</tr>
<tr>
<td></td>
<td>ddd</td>
<td>Sun Mon ... Fri Sat</td>
</tr>
<tr>
<td></td>
<td>dddd</td>
<td>Sunday Monday ... Friday Saturday</td>
</tr>
<tr>
<td><b class="notranslate">Day of Week (Locale)</b></td>
<td>e</td>
<td>0 1 ... 5 6</td>
</tr>
<tr>
<td><b class="notranslate">Day of Week (ISO)</b></td>
<td>E</td>
<td>1 2 ... 6 7</td>
</tr>
<tr>
<td><b class="notranslate">Week of Year</b></td>
<td>w</td>
<td>1 2 ... 52 53</td>
</tr>
<tr>
<td></td>
<td>wo</td>
<td>1st 2nd ... 52nd 53rd</td>
</tr>
<tr>
<td></td>
<td>ww</td>
<td>01 02 ... 52 53</td>
</tr>
<tr>
<td><b class="notranslate">Week of Year (ISO)</b></td>
<td>W</td>
<td>1 2 ... 52 53</td>
</tr>
<tr>
<td></td>
<td>Wo</td>
<td>1st 2nd ... 52nd 53rd</td>
</tr>
<tr>
<td></td>
<td>WW</td>
<td>01 02 ... 52 53</td>
</tr>
<tr>
<td><b class="notranslate">Year</b></td>
<td>YY</td>
<td>70 71 ... 29 30</td>
</tr>
<tr>
<td></td>
<td>YYYY</td>
<td>1970 1971 ... 2029 2030</td>
</tr>
<tr>
<td></td>
<td>YYYYYY</td>
<td>-001970 -001971 ... +001907 +001971 <br> <b class="notranslate">Note:</b> <a href="javascript:window.open('https://tc39.es/ecma262/#sec-expanded-years');" target="_blank" rel="noopener noreferrer">Expanded Years <i class="fa fa-external-link"></i></a> (Covering the full time value range of approximately 273,790 years forward or backward from 01 January, 1970) </td>
</tr>
<tr>
<td></td>
<td>Y</td>
<td>1970 1971 ... 9999 +10000 +10001 <br> <b class="notranslate">Note:</b> This complies with the ISO 8601 standard for dates past the year 9999 </td>
</tr>
<tr>
<td><b class="notranslate">Era Year</b></td>
<td>y</td>
<td>1 2 ... 2020 ... </td>
</tr>
<tr>
<td><b class="notranslate">Era</b></td>
<td>N</td>
<td> BC AD<br> <b class="notranslate">Note:</b> Abbr era name </td>
</tr>
<tr>
<td></td>
<td>NN</td>
<td> BC AD<br> <b class="notranslate">Note:</b> Narrow era name </td>
</tr>
<tr>
<td></td>
<td>NNN</td>
<td> Before Christ, Anno Domini <br> <b class="notranslate">Note:</b> Full era name </td>
</tr>
<tr>
<td><b class="notranslate">Week Year</b></td>
<td>gg</td>
<td>70 71 ... 29 30</td>
</tr>
<tr>
<td></td>
<td>gggg</td>
<td>1970 1971 ... 2029 2030</td>
</tr>
<tr>
<td><b class="notranslate">Week Year (ISO)</b></td>
<td>GG</td>
<td>70 71 ... 29 30</td>
</tr>
<tr>
<td></td>
<td>GGGG</td>
<td>1970 1971 ... 2029 2030</td>
</tr>
<tr>
<td><b class="notranslate">AM/PM</b></td>
<td>A</td>
<td>AM PM</td>
</tr>
<tr>
<td></td>
<td>a</td>
<td>am pm</td>
</tr>
<tr>
<td><b class="notranslate">Hour</b></td>
<td>H</td>
<td>0 1 ... 22 23</td>
</tr>
<tr>
<td></td>
<td>HH</td>
<td>00 01 ... 22 23</td>
</tr>
<tr>
<td></td>
<td>h</td>
<td>1 2 ... 11 12</td>
</tr>
<tr>
<td></td>
<td>hh</td>
<td>01 02 ... 11 12</td>
</tr>
 <tr>
<td></td>
<td>k</td>
<td>1 2 ... 23 24</td>
</tr>
<tr>
<td></td>
<td>kk</td>
<td>01 02 ... 23 24</td>
</tr>
<tr>
<td><b class="notranslate">Minute</b></td>
<td>m</td>
<td>0 1 ... 58 59</td>
</tr>
<tr>
<td></td>
<td>mm</td>
<td>00 01 ... 58 59</td>
</tr>
<tr>
<td><b class="notranslate">Second</b></td>
<td>s</td>
<td>0 1 ... 58 59</td>
</tr>
<tr>
<td></td>
<td>ss</td>
<td>00 01 ... 58 59</td>
</tr>
<tr>
<td><b class="notranslate">Fractional Second</b></td>
<td>S</td>
<td>0 1 ... 8 9</td>
</tr>
<tr>
<td></td>
<td>SS</td>
<td>00 01 ... 98 99</td>
</tr>
<tr>
<td></td>
<td>SSS</td>
<td>000 001 ... 998 999</td>
</tr>
<tr>
<td></td>
<td>SSSS ... SSSSSSSSS</td>
<td>000[0..] 001[0..] ... 998[0..] 999[0..]</td>
</tr>
<tr>
<td><b class="notranslate">Time Zone</b></td>
<td>z or zz</td>
<td> EST CST ... MST PST <br> <b class="notranslate">Note:</b> as of <b class="notranslate">1.6.0</b>, the z/zz format tokens have been deprecated from plain moment objects. <a href="javascript:window.open('https://github.com/moment/moment/issues/162');" target="_blank" rel="noopener noreferrer">Read more about it here. <i class="fa fa-external-link"></i></a> However, they *do* work if you are using a specific time zone with the moment-timezone addon. </td>
</tr>
<tr>
<td></td>
<td>Z</td>
<td>-07:00 -06:00 ... +06:00 +07:00</td>
</tr>
<tr>
<td></td>
<td>ZZ</td>
<td> -0700 -0600 ... +0600 +0700 </td>
</tr>
<tr>
<td><b class="notranslate">Unix Timestamp</b></td>
<td>X</td>
<td>1360013296</td>
</tr>
<tr>
<td><b class="notranslate">Unix Millisecond Timestamp</b></td>
<td>x</td>
<td>1360013296123</td>
</tr>
</tbody>
</table>
<p><code class="notranslate">X</code> was added in <strong>2.0.0</strong>.</p>
<p><code class="notranslate">e E gg gggg GG GGGG</code> were added in <strong>2.1.0</strong>.</p>
<p><code class="notranslate">x</code> was added in <strong>2.8.4</strong>.</p>
<p><code class="notranslate">SSSS</code> to <code class="notranslate">SSSSSSSSS</code> were added in <strong>2.10.5</strong>. They display 3 significant digits and the rest is filled with zeros.</p>
<p><code class="notranslate">k</code> and <code class="notranslate">kk</code> were added in <strong>2.13.0</strong>.</p>
<h4 id="Localized-formats">Localized formats</h4>
<p>Because preferred formatting differs based on locale, there are a few tokens that can be used to format a moment based on its locale.</p>
<p>There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart.</p>
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td><b class="notranslate">Time</b></td>
<td>LT</td>
<td>8:30 PM</td>
</tr>
<tr>
<td><b class="notranslate">Time with seconds</b></td>
<td>LTS</td>
<td>8:30:25 PM</td>
</tr>
<tr>
<td><b class="notranslate">Month numeral, day of month, year</b></td>
<td>L</td>
<td>09/04/1986</td>
</tr>
<tr>
<td></td>
<td>l</td>
<td>9/4/1986</td>
</tr>
<tr>
<td><b class="notranslate">Month name, day of month, year</b></td>
<td>LL</td>
<td>September 4, 1986</td>
</tr>
<tr>
<td></td>
<td>ll</td>
<td>Sep 4, 1986</td>
</tr>
<tr>
<td><b class="notranslate">Month name, day of month, year, time</b></td>
<td>LLL</td>
<td>September 4, 1986 8:30 PM</td>
</tr>
<tr>
<td></td>
<td>lll</td>
<td>Sep 4, 1986 8:30 PM</td>
</tr>
<tr>
<td><b class="notranslate">Month name, day of month, day of week, year, time</b></td>
<td>LLLL</td>
 <td>Thursday, September 4, 1986 8:30 PM</td>
</tr>
<tr>
<td></td>
<td>llll</td>
<td>Thu, Sep 4, 1986 8:30 PM</td>
</tr>
</tbody>
</table>
<p><code class="notranslate">l ll lll llll</code> are available in <strong>2.0.0</strong>. <code class="notranslate">LTS</code> was added in <strong>2.8.4</strong>.</p>
<h4 id="Escaping-characters">Escaping characters</h4>
<p>To escape characters in format strings, you can wrap the characters in square brackets.</p>
<pre class="notranslate"><code class="language-javascript">moment().format('[today] dddd'); // 'today Sunday'
</code></pre>
<h4 id="Similarities-and-differences-with-LDML">Similarities and differences with LDML</h4>
<p><strong>Note:</strong> While these date formats are very similar to LDML date formats, there are a few minor differences regarding day of month, day of year, and day of week.</p>
<p>For a breakdown of a few different date formatting tokens across different locales, see <a href="javascript:window.open('https://docs.google.com/spreadsheet/ccc?key=0AtgZluze7WMJdDBOLUZfSFIzenIwOHNjaWZoeGFqbWc&amp;amp;hl=en_US#gid=0');" target="_blank" rel="noopener noreferrer">this chart of date formatting tokens. <i class="fa fa-external-link"></i></a></p>
<h4 id="Formatting-speed">Formatting speed</h4>
<p>To compare Moment.js formatting speed against other libraries, check out <a href="javascript:window.open('https://jsperf.com/date-formatting/49');" target="_blank" rel="noopener noreferrer">this comparison against other libraries <i class="fa fa-external-link"></i></a>.</p>
<h4 id="Other-tokens">Other tokens</h4>
<p>If you are more comfortable working with strftime instead of LDML-like parsing tokens, you can use Ben Oakes' plugin. <a href="javascript:window.open('https://github.com/benjaminoakes/moment-strftime');" target="_blank" rel="noopener noreferrer">benjaminoakes/moment-strftime <i class="fa fa-external-link"></i></a>.</p>
<h4 id="Default-format">Default format</h4>
<p>Calling <code class="notranslate">moment#format</code> without a format will default to <code class="notranslate">moment.defaultFormat</code>. Out of the box, <code class="notranslate">moment.defaultFormat</code> is the ISO8601 format <code class="notranslate">YYYY-MM-DDTHH:mm:ssZ</code>.</p>
<p>As of version <strong>2.13.0</strong>, when in UTC mode, the default format is governed by <code class="notranslate">moment.defaultFormatUtc</code> which is in the format <code class="notranslate">YYYY-MM-DDTHH:mm:ss[Z]</code>. This returns <code class="notranslate">Z</code> as the offset, instead of <code class="notranslate">+00:00</code>.</p>
<p>In certain instances, a local timezone (such as <code class="notranslate">Atlantic/Reykjavik</code>) may have a zero offset, and will be considered to be UTC. In such cases, it may be useful to set <code class="notranslate">moment.defaultFormat</code> and <code class="notranslate">moment.defaultFormatUtc</code> to use the same formatting.</p>
<p>Changing the value of <code class="notranslate">moment.defaultFormat</code> will only affect formatting, and will not affect parsing. for example:</p>
<pre class="notranslate"><code class="language-javascript">moment.defaultFormat = "DD.MM.YYYY HH:mm";
// parse with .toDate()
moment('20.07.2018 09:19').toDate() // Invalid date
// format the date string with the new defaultFormat then parse
moment('20.07.2018 09:19', moment.defaultFormat).toDate() // Fri Jul 20 2018 09:19:00 GMT+0300
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/fromnow/" name="/displaying/fromnow/"></a>
<h3 class="docs-method-title" id="Time-from-now-1.0.0+"> <a href="#/displaying/fromnow/">Time from now</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/02-fromnow.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().fromNow();
moment().fromNow(Boolean);
</code></pre>
</div>
<p>A common way of displaying time is handled by <code class="notranslate">moment#fromNow</code>. This is sometimes called timeago or relative time.</p>
<pre class="notranslate"><code class="language-javascript">moment([2007, 0, 29]).fromNow(); // 4 years ago
</code></pre>
<p>If you pass <code class="notranslate">true</code>, you can get the value without the suffix.</p>
<pre class="notranslate"><code class="language-javascript">moment([2007, 0, 29]).fromNow();     // 4 years ago
moment([2007, 0, 29]).fromNow(true); // 4 years
</code></pre>
<p>The base strings are <a href="#/customization/relative-time/">customized by the current locale</a>. Time is rounded to the nearest second.</p>
<p>The breakdown of which string is displayed for each length of time is outlined in the table below.</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Range</th>
<th>Key</th>
<th>Sample Output</th>
</tr>
</thead>
<tbody>
<tr>
<td>0 to 44 seconds</td>
<td>s</td>
<td>a few seconds ago</td>
</tr>
<tr>
<td><i>unset</i></td>
<td>ss</td>
<td>44 seconds ago</td>
</tr>
<tr>
<td>45 to 89 seconds</td>
<td>m</td>
<td>a minute ago</td>
</tr>
<tr>
<td>90 seconds to 44 minutes</td>
<td>mm</td>
<td>2 minutes ago ... 44 minutes ago</td>
</tr>
<tr>
<td>45 to 89 minutes</td>
<td>h</td>
<td>an hour ago</td>
</tr>
<tr>
<td>90 minutes to 21 hours </td>
<td>hh</td>
<td>2 hours ago ... 21 hours ago</td>
</tr>
<tr>
<td>22 to 35 hours</td>
<td>d</td>
<td>a day ago</td>
</tr>
<tr>
<td>36 hours to 25 days</td>
<td>dd</td>
<td>2 days ago ... 25 days ago</td>
</tr>
<tr>
<td>26 to 45 days</td>
<td>M</td>
<td>a month ago</td>
</tr>
<tr>
<td>45 to 319 days</td>
<td>MM</td>
<td>2 months ago ... 10 months ago</td>
</tr>
<tr>
<td>320 to 547 days (1.5 years)</td>
<td>y</td>
<td>a year ago</td>
</tr>
<tr>
<td>548 days+</td>
<td>yy</td>
<td>2 years ago ... 20 years ago</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> From version <strong>2.10.3</strong>, if the target moment object is invalid the result is the localized Invalid date string.</p>
<p><strong>Note:</strong> The <code class="notranslate">ss</code> key was added in <strong>2.18.0</strong>. It is an optional threshold. It will never display UNLESS the user manually sets the ss threshold. Until the <code class="notranslate">ss</code> threshold is set, it defaults to the value of the <code class="notranslate">s</code> threshold minus 1 (so, invisible to the user).</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/from/" name="/displaying/from/"></a>
<h3 class="docs-method-title" id="Time-from-X-1.0.0+"> <a href="#/displaying/from/">Time from X</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/03-from.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().from(Moment|String|Number|Date|Array);
moment().from(Moment|String|Number|Date|Array, Boolean);
</code></pre>
</div>
<p>You may want to display a moment in relation to a time other than now. In that case, you can use <code class="notranslate">moment#from</code>.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.from(b) // "a day ago"
</code></pre>
<p>The first parameter is anything you can pass to <code class="notranslate">moment()</code> or an actual <code class="notranslate">Moment</code>.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.from(b);                     // "a day ago"
a.from([2007, 0, 29]);         // "a day ago"
a.from(new Date(2007, 0, 29)); // "a day ago"
a.from("2007-01-29");          // "a day ago"
</code></pre>
<p>Like <code class="notranslate">moment#fromNow</code>, passing <code class="notranslate">true</code> as the second parameter returns value without the suffix. This is useful wherever you need to have a human readable length of time.</p>
<pre class="notranslate"><code class="language-javascript">var start = moment([2007, 0, 5]);
var end   = moment([2007, 0, 10]);
end.from(start);       // "in 5 days"
end.from(start, true); // "5 days"
</code></pre>
<p>From version <strong>2.10.3</strong>, if any of the endpoints are invalid the result is the localized Invalid date string.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/tonow/" name="/displaying/tonow/"></a>
<h3 class="docs-method-title" id="Time-to-now-2.10.3+"> <a href="#/displaying/tonow/">Time to now</a> <span>2.10.3+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/04-tonow.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().toNow();
moment().toNow(Boolean);
</code></pre>
</div>
<p>A common way of displaying time is handled by <code class="notranslate">moment#toNow</code>. This is sometimes called timeago or relative time.</p>
<p>This is similar to <a href="#/displaying/fromnow/"><code class="notranslate">moment.fromNow</code></a>, but gives the opposite interval: <code class="notranslate">a.fromNow() = - a.toNow()</code>.</p>
<p>This is similar to <a href="#/displaying/to/"><code class="notranslate">moment.to</code></a>, but is special-cased for the current time. Use <code class="notranslate">moment.to</code>, if you want to control the two end points of the interval.</p>
<pre class="notranslate"><code class="language-javascript">moment([2007, 0, 29]).toNow(); // in 4 years
</code></pre>
<p>If you pass <code class="notranslate">true</code>, you can get the value without the prefix.</p>
<pre class="notranslate"><code class="language-javascript">moment([2007, 0, 29]).toNow();     // in 4 years
moment([2007, 0, 29]).toNow(true); // 4 years
</code></pre>
<p>The base strings are <a href="#/customization/relative-time/">customized by the current locale</a>.</p>
<p>The breakdown of which string is displayed for each length of time is outlined in the table below.</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Range</th>
<th>Key</th>
<th>Sample Output</th>
</tr>
</thead>
<tbody>
<tr>
<td>0 to 44 seconds</td>
<td>s</td>
<td>in seconds</td>
</tr>
<tr>
<td>45 to 89 seconds</td>
<td>m</td>
<td>in a minute</td>
</tr>
<tr>
<td>90 seconds to 44 minutes</td>
<td>mm</td>
<td>in 2 minutes ... in 44 minutes</td>
</tr>
<tr>
<td>45 to 89 minutes</td>
<td>h</td>
<td>in an hour</td>
</tr>
<tr>
<td>90 minutes to 21 hours </td>
<td>hh</td>
<td>in 2 hours ... in 21 hours</td>
</tr>
<tr>
<td>22 to 35 hours</td>
<td>d</td>
<td>in a day</td>
</tr>
<tr>
<td>36 hours to 25 days</td>
<td>dd</td>
<td>in 2 days ... in 25 days</td>
</tr>
<tr>
<td>26 to 45 days</td>
<td>M</td>
<td>in a month</td>
</tr>
<tr>
<td>45 to 319 days</td>
<td>MM</td>
<td>in 2 months ... in 10 months</td>
</tr>
<tr>
<td>320 to 547 days (1.5 years)</td>
<td>y</td>
<td>in a year</td>
</tr>
<tr>
<td>548 days+</td>
<td>yy</td>
<td>in 2 years ... in 20 years</td>
</tr>
</tbody>
</table>
<p>From version <strong>2.10.3</strong>, if the target moment object is invalid the result is the localized Invalid date string.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/to/" name="/displaying/to/"></a>
<h3 class="docs-method-title" id="Time-to-X-2.10.3+"> <a href="#/displaying/to/">Time to X</a> <span>2.10.3+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/05-to.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().to(Moment|String|Number|Date|Array);
moment().to(Moment|String|Number|Date|Array, Boolean);
</code></pre>
</div>
<p>You may want to display a moment in relation to a time other than now. In that case, you can use <code class="notranslate">moment#to</code>.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.to(b) // "in a day"
</code></pre>
<p>The first parameter is anything you can pass to <code class="notranslate">moment()</code> or an actual <code class="notranslate">Moment</code>.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2007, 0, 28]);
var b = moment([2007, 0, 29]);
a.to(b);                     // "in a day"
a.to([2007, 0, 29]);         // "in a day"
a.to(new Date(2007, 0, 29)); // "in a day"
a.to("2007-01-29");          // "in a day"
</code></pre>
<p>Like <code class="notranslate">moment#toNow</code>, passing <code class="notranslate">true</code> as the second parameter returns value without the suffix. This is useful wherever you need to have a human readable length of time.</p>
<pre class="notranslate"><code class="language-javascript">var start = moment([2007, 0, 5]);
var end   = moment([2007, 0, 10]);
end.to(start);       // "5 days ago"
end.to(start, true); // "5 days"
</code></pre>
<p>From version <strong>2.10.3</strong>, if any of the endpoints are invalid the result is the localized Invalid date string.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/calendar-time/" name="/displaying/calendar-time/"></a>
<h3 class="docs-method-title" id="Calendar-Time-1.3.0+"> <a href="#/displaying/calendar-time/">Calendar Time</a> <span>1.3.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/06-calendar-time.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().calendar();
moment().calendar(referenceDay);
moment().calendar(referenceDay, formats);  // from 2.10.5
moment().calendar(formats);  // from 2.25.0
</code></pre>
</div>
<p>Calendar time displays time relative to a given <code class="notranslate">referenceDay</code> (defaults to the start of today), but does so slightly differently than <code class="notranslate">moment#fromNow</code>.</p>
<p><code class="notranslate">moment#calendar</code> will format a date with different strings depending on how close to <code class="notranslate">referenceDay</code>'s date (today by default) the date is.</p>
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td>Last week</td>
<td>Last Monday at 2:30 AM</td>
</tr>
<tr>
<td>The day before</td>
<td>Yesterday at 2:30 AM</td>
</tr>
<tr>
<td>The same day</td>
<td>Today at 2:30 AM</td>
</tr>
<tr>
<td>The next day</td>
<td>Tomorrow at 2:30 AM</td>
</tr>
<tr>
<td>The next week</td>
<td>Sunday at 2:30 AM</td>
</tr>
<tr>
<td>Everything else</td>
<td>7/10/2011</td>
</tr>
</tbody>
</table>
<p>These strings are localized, and <a href="#/customization/calendar/">can be customized</a>.</p>
<p>From <strong>2.10.5</strong> moment supports specifying calendar output formats per invocation:</p>
<pre class="notranslate"><code class="language-javascript">moment().calendar(null, {
    sameDay: '[Today]',
    nextDay: '[Tomorrow]',
    nextWeek: 'dddd',
    lastDay: '[Yesterday]',
    lastWeek: '[Last] dddd',
    sameElse: 'DD/MM/YYYY'
});
</code></pre>
<p><code class="notranslate">sameElse</code> is used as the format when the moment is more than a week away from the <code class="notranslate">referenceDay</code></p>
<p><strong>Note:</strong> From version <strong>2.14.0</strong> the formats argument to calendar can be a callback that is executed within the moment context with a single argument now:</p>
<pre class="notranslate"><code class="language-javascript">moment().calendar(null, {
  sameDay: function (now) {
    if (this.isBefore(now)) {
      return '[Will Happen Today]';
    } else {
      return '[Happened Today]';
    }
    /* ... */
  }
});
</code></pre>
<p><strong>Note:</strong> From version <strong>2.25.0</strong> you can only pass a formats argument, it could be an object of strings and functions:</p>
<pre class="notranslate"><code class="language-javascript">moment().calendar({
    sameDay: '[Today]',
    nextDay: '[Tomorrow]',
    nextWeek: 'dddd',
    lastDay: '[Yesterday]',
    lastWeek: '[Last] dddd',
    sameElse: 'DD/MM/YYYY'
});

moment().calendar({
  sameDay: function (now) {
    if (this.isBefore(now)) {
      return '[Will Happen Today]';
    } else {
      return '[Happened Today]';
    }
    /* ... */
  }
});
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/difference/" name="/displaying/difference/"></a>
<h3 class="docs-method-title" id="Difference-1.0.0+"> <a href="#/displaying/difference/">Difference</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/07-difference.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().diff(Moment|String|Number|Date|Array);
moment().diff(Moment|String|Number|Date|Array, String);
moment().diff(Moment|String|Number|Date|Array, String, Boolean);
</code></pre>
</div>
<p>To get the difference in milliseconds, use <code class="notranslate">moment#diff</code> like you would use <code class="notranslate">moment#from</code>.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.diff(b) // 86400000
</code></pre>
<p>To get the difference in another unit of measurement, pass that measurement as the second argument.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.diff(b, 'days') // 1
</code></pre>
<p>To get the duration of a difference between two moments, you can pass <code class="notranslate">diff</code> as an argument into <code class="notranslate">moment#duration</code>. See the docs on <a href="#/durations/diffing/">moment#duration</a> for more info.</p>
<p>The supported measurements are <code class="notranslate">years</code>, <code class="notranslate">months</code>, <code class="notranslate">weeks</code>, <code class="notranslate">days</code>, <code class="notranslate">hours</code>, <code class="notranslate">minutes</code>, and <code class="notranslate">seconds</code>. For ease of development, the singular forms are supported as of <strong>2.0.0</strong>. Units of measurement other than milliseconds are available in version <strong>1.1.1</strong>.</p>
<p>By default, <code class="notranslate">moment#diff</code> will truncate the result to zero decimal places, returning an integer. If you want a floating point number, pass <code class="notranslate">true</code> as the third argument. Before <strong>2.0.0</strong>, <code class="notranslate">moment#diff</code> returned a number rounded to the nearest integer, not a truncated number.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment([2008, 9]);
var b = moment([2007, 0]);
a.diff(b, 'years');       // 1
a.diff(b, 'years', true); // 1.75
</code></pre>
<p>If the moment is earlier than the moment you are passing to <code class="notranslate">moment.fn.diff</code>, the return value will be negative.</p>
<pre class="notranslate"><code class="language-javascript">var a = moment();
var b = moment().add(1, 'seconds');
a.diff(b) // -1000
b.diff(a) // 1000
</code></pre>
<p>An easy way to think of this is by replacing <code class="notranslate">.diff(</code> with a minus operator.</p>
<pre class="notranslate"><code class="language-javascript">          // a &lt; b
a.diff(b) // a - b &lt; 0
b.diff(a) // b - a &gt; 0
</code></pre>
<h4 id="Month-and-year-diffs">Month and year diffs</h4>
<p><code class="notranslate">moment#diff</code> has some special handling for month and year diffs. It is optimized to ensure that two months with the same date are always a whole number apart.</p>
<p>So Jan 15 to Feb 15 should be exactly 1 month.</p>
<p>Feb 28 to Mar 28 should be exactly 1 month.</p>
<p>Feb 28 2011 to Feb 28 2012 should be exactly 1 year.</p>
<p><a href="javascript:window.open('https://github.com/moment/moment/pull/571');" target="_blank" rel="noopener noreferrer">See more discussion on the month and year diffs here <i class="fa fa-external-link"></i></a></p>
<p>This change to month and year diffs was made in <strong>2.0.0</strong>. As of version <strong>2.9.0</strong> diff also support quarter unit.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/unix-timestamp-milliseconds/" name="/displaying/unix-timestamp-milliseconds/"></a>
<h3 class="docs-method-title" id="Unix-Timestamp-(milliseconds)-1.0.0+"> <a href="#/displaying/unix-timestamp-milliseconds/">Unix Timestamp (milliseconds)</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/08-unix-timestamp-milliseconds.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().valueOf();
+moment();
</code></pre>
</div>
<p><code class="notranslate">moment#valueOf</code> simply outputs the number of milliseconds since the Unix Epoch, just like <code class="notranslate">Date#valueOf</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment(1318874398806).valueOf(); // 1318874398806
+moment(1318874398806); // 1318874398806
</code></pre>
<p>To get a Unix timestamp (the number of seconds since the epoch) from a <code class="notranslate">Moment</code>, use <code class="notranslate">moment#unix</code>.</p>
<p><a href="javascript:window.open('https://www.ecma-international.org/ecma-262/6.0/#sec-time-values-and-time-range');" target="_blank" rel="noopener noreferrer"> Note: ECMAScript calls this a "Time Value" <i class="fa fa-external-link"></i></a></p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/unix-timestamp/" name="/displaying/unix-timestamp/"></a>
<h3 class="docs-method-title" id="Unix-Timestamp-(seconds)-1.6.0+"> <a href="#/displaying/unix-timestamp/">Unix Timestamp (seconds)</a> <span>1.6.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/09-unix-timestamp.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().unix();
</code></pre>
</div>
<p><code class="notranslate">moment#unix</code> outputs a Unix timestamp (the number of seconds since the Unix Epoch).</p>
<pre class="notranslate"><code class="language-javascript">moment(1318874398806).unix(); // 1318874398
</code></pre>
<p>This value is floored to the nearest second, and does not include a milliseconds component.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/days-in-month/" name="/displaying/days-in-month/"></a>
<h3 class="docs-method-title" id="Days-in-Month-1.5.0+"> <a href="#/displaying/days-in-month/">Days in Month</a> <span>1.5.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/10-days-in-month.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().daysInMonth();
</code></pre>
</div>
<p>Get the number of days in the current month.</p>
<pre class="notranslate"><code class="language-javascript">moment("2012-02", "YYYY-MM").daysInMonth() // 29
moment("2012-01", "YYYY-MM").daysInMonth() // 31
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/as-javascript-date/" name="/displaying/as-javascript-date/"></a>
<h3 class="docs-method-title" id="As-Javascript-Date-1.0.0+"> <a href="#/displaying/as-javascript-date/">As Javascript Date</a> <span>1.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/11-as-javascript-date.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().toDate();
</code></pre>
</div>
<p>To get a copy of the native Date object that Moment.js wraps, use <code class="notranslate">moment#toDate</code>.</p>
<p>This will return a copy of the <code class="notranslate">Date</code> that the moment uses, so any changes to that <code class="notranslate">Date</code> will not cause moment to change. If you want to change the moment <code class="notranslate">Date</code>, see <code class="notranslate">moment#manipulate</code> or <code class="notranslate">moment#set</code>.</p>
<p><code class="notranslate">moment#native</code> has been replaced by <code class="notranslate">moment#toDate</code> and has been deprecated as of <strong>1.6.0</strong>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/as-array/" name="/displaying/as-array/"></a>
<h3 class="docs-method-title" id="As-Array-1.7.0+"> <a href="#/displaying/as-array/">As Array</a> <span>1.7.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/12-as-array.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().toArray();
</code></pre>
</div>
<p>This returns an array that mirrors the parameters from <code class="notranslate">new Date()</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment().toArray(); // [2013, 1, 4, 14, 40, 16, 154];
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/as-json/" name="/displaying/as-json/"></a>
<h3 class="docs-method-title" id="As-JSON-2.0.0+"> <a href="#/displaying/as-json/">As JSON</a> <span>2.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/13-as-json.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().toJSON();
</code></pre>
</div>
<p>When serializing an object to JSON, if there is a <code class="notranslate">Moment</code> object, it will be represented as an ISO8601 string, adjusted to UTC.</p>
<pre class="notranslate"><code class="language-javascript">JSON.stringify({
    postDate : moment()
}); // '{"postDate":"2013-02-04T22:44:30.652Z"}'
</code></pre>
<p>If instead you would like an ISO8601 string that reflects the moment's <code class="notranslate">utcOffset()</code>, then you can modify the <code class="notranslate">toJSON</code> function like this:</p>
<pre class="notranslate"><code class="language-javascript">moment.fn.toJSON = function() { return this.format(); }
</code></pre>
<p>This changes the behavior as follows:</p>
<pre class="notranslate"><code class="language-javascript">JSON.stringify({
    postDate : moment()
}); // '{"postDate":"2013-02-04T14:44:30-08:00"}'
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/as-iso-string/" name="/displaying/as-iso-string/"></a>
<h3 class="docs-method-title" id="As-ISO-8601-String-2.1.0+"> <a href="#/displaying/as-iso-string/">As ISO 8601 String</a> <span>2.1.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/14-as-iso-string.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().toISOString();
moment().toISOString(keepOffset); // from 2.20.0
</code></pre>
</div>
<p>Formats a string to the ISO8601 standard.</p>
<pre class="notranslate"><code class="language-javascript">moment().toISOString() // 2013-02-04T22:44:30.652Z
</code></pre>
<p>Note that <code class="notranslate">.toISOString()</code> returns a timestamp in UTC, even if the moment in question is in local mode. This is done to provide consistency with the specification for native JavaScript Date <code class="notranslate">.toISOString()</code>, as outlined in <a href="javascript:window.open('https://www.ecma-international.org/ecma-262/6.0/#sec-date.prototype.toisostring');" target="_blank" rel="noopener noreferrer"> the ES2015 specification <i class="fa fa-external-link"></i></a>. From version <strong>2.20.0</strong>, you may call <code class="notranslate">.toISOString(true)</code> to prevent UTC conversion.</p>
<p>From version <strong>2.8.4</strong> the native <code class="notranslate">Date.prototype.toISOString</code> is used if available, for performance reasons.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/as-object/" name="/displaying/as-object/"></a>
<h3 class="docs-method-title" id="As-Object-2.10.5+"> <a href="#/displaying/as-object/">As Object</a> <span>2.10.5+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/15-as-object.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().toObject();
</code></pre>
</div>
<p>This returns an object containing year, month, day-of-month, hour, minute, seconds, milliseconds.</p>
<pre class="notranslate"><code class="language-javascript">moment().toObject()  // {
                     //     years: 2015
                     //     months: 6
                     //     date: 26,
                     //     hours: 1,
                     //     minutes: 53,
                     //     seconds: 14,
                     //     milliseconds: 600
                     // }
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/as-string/" name="/displaying/as-string/"></a>
<h3 class="docs-method-title" id="As-String-2.1.0+"> <a href="#/displaying/as-string/">As String</a> <span>2.1.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/16-as-string.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().toString();
</code></pre>
</div>
<p>Returns an english string in a similar format to JS Date's <code class="notranslate">.toString()</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment().toString() // "Sat Apr 30 2016 16:59:46 GMT-0500"
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/displaying/inspect/" name="/displaying/inspect/"></a>
<h3 class="docs-method-title" id="Inspect-2.16.0+"> <a href="#/displaying/inspect/">Inspect</a> <span>2.16.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/04-displaying/17-inspect.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().inspect();
</code></pre>
</div>
<p>Returns a machine readable string, that can be evaluated to produce the same moment. Because of the name its also used in node interactive shell to display objects.</p>
<pre class="notranslate"><code class="language-javascript">moment().inspect() // 'moment("2016-11-09T22:23:27.861")'
moment.utc().inspect() // 'moment.utc("2016-11-10T06:24:10.638+00:00")'
moment.parseZone('2016-11-10T06:24:12.958+05:00').inspect() // 'moment.parseZone("2016-11-10T06:24:12.958+05:00")'
moment(new Date('nope')).inspect() // 'moment.invalid(/* Invalid Date */)'
moment('blah', 'YYYY').inspect() // 'moment.invalid(/* blah */)'
</code></pre>
<p><strong>Note:</strong> This function is mostly intended for debugging, not all cases are handled precisely.</p>
</div>
</article>
<article class="docs-section">
<a class="docs-section-target" id="/query/" name="/query/"></a>
<h2 class="docs-section-title" id="Query"><a href="#/query/">Query</a></h2>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/intro/" name="/query/intro/"></a>
<div class="docs-method-prose">
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/is-before/" name="/query/is-before/"></a>
<h3 class="docs-method-title" id="Is-Before-2.0.0+"> <a href="#/query/is-before/">Is Before</a> <span>2.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/05-query/01-is-before.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isBefore(Moment|String|Number|Date|Array);
moment().isBefore(Moment|String|Number|Date|Array, String);
</code></pre>
</div>
<p>Check if a moment is before another moment. The first argument will be parsed as a moment, if not already so.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isBefore('2010-10-21'); // true
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.</p>
<p>As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isBefore('2010-12-31', 'year'); // false
moment('2010-10-20').isBefore('2011-01-01', 'year'); // true
</code></pre>
<p>Like <code class="notranslate">moment#isAfter</code> and <code class="notranslate">moment#isSame</code>, any of the units of time that are supported for <code class="notranslate">moment#startOf</code> are supported for <code class="notranslate">moment#isBefore</code>.</p>
<pre class="notranslate"><code>year month week isoWeek day hour minute second
</code></pre>
<p>If nothing is passed to <code class="notranslate">moment#isBefore</code>, it will default to the current time.</p>
<p><em>NOTE</em>: <code class="notranslate">moment().isBefore()</code> has undefined behavior and should not be used! If the code runs fast the initial created moment would be the same as the one created in isBefore to perform the check, so the result would be <code class="notranslate">false</code>. But if the code runs slower it's possible that the moment created in isBefore is measurably after the one created in <code class="notranslate">moment()</code>, so the call would return <code class="notranslate">true</code>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/is-same/" name="/query/is-same/"></a>
<h3 class="docs-method-title" id="Is-Same-2.0.0+"> <a href="#/query/is-same/">Is Same</a> <span>2.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/05-query/02-is-same.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isSame(Moment|String|Number|Date|Array);
moment().isSame(Moment|String|Number|Date|Array, String);
</code></pre>
</div>
<p>Check if a moment is the same as another moment. The first argument will be parsed as a moment, if not already so.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isSame('2010-10-20'); // true
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isSame('2009-12-31', 'year');  // false
moment('2010-10-20').isSame('2010-01-01', 'year');  // true
moment('2010-10-20').isSame('2010-12-31', 'year');  // true
moment('2010-10-20').isSame('2011-01-01', 'year');  // false
</code></pre>
<p>When including a second parameter, it will match all units equal or larger. Passing in <code class="notranslate">month</code> will check <code class="notranslate">month</code> and <code class="notranslate">year</code>. Passing in <code class="notranslate">day</code> will check <code class="notranslate">day</code>, <code class="notranslate">month</code>, and <code class="notranslate">year</code>.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-01-01').isSame('2011-01-01', 'month'); // false, different year
moment('2010-01-01').isSame('2010-02-01', 'day');   // false, different month
</code></pre>
<p>Like <code class="notranslate">moment#isAfter</code> and <code class="notranslate">moment#isBefore</code>, any of the units of time that are supported for <code class="notranslate">moment#startOf</code> are supported for <code class="notranslate">moment#isSame</code>.</p>
<pre class="notranslate"><code>year month week isoWeek day hour minute second
</code></pre>
<p>If the two moments have different timezones, the timezone of the first moment will be used for the comparison.</p>
<pre class="notranslate"><code class="language-javascript">// Note: Australia/Sydney is UTC+11:00 on these dates
moment.tz("2018-11-09T10:00:00", "Australia/Sydney").isSame(moment.tz("2018-11-08T12:00:00", "UTC"), "day"); // false
moment.tz("2018-11-08T12:00:00", "UTC").isSame(moment.tz("2018-11-09T10:00:00", "Australia/Sydney"), "day"); // true
</code></pre>
<p><em>NOTE</em>: <code class="notranslate">moment().isSame()</code> has undefined behavior and should not be used! If the code runs fast the initial created moment would be the same as the one created in isSame to perform the check, so the result would be <code class="notranslate">true</code>. But if the code runs slower it's possible that the moment created in isSame is measurably after the one created in <code class="notranslate">moment()</code>, so the call would return <code class="notranslate">false</code>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/is-after/" name="/query/is-after/"></a>
<h3 class="docs-method-title" id="Is-After-2.0.0+"> <a href="#/query/is-after/">Is After</a> <span>2.0.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/05-query/03-is-after.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isAfter(Moment|String|Number|Date|Array);
moment().isAfter(Moment|String|Number|Date|Array, String);
</code></pre>
</div>
<p>Check if a moment is after another moment. The first argument will be parsed as a moment, if not already so.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isAfter('2010-10-19'); // true
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.</p>
<p>As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isAfter('2010-01-01', 'year'); // false
moment('2010-10-20').isAfter('2009-12-31', 'year'); // true
</code></pre>
<p>Like <code class="notranslate">moment#isSame</code> and <code class="notranslate">moment#isBefore</code>, any of the units of time that are supported for <code class="notranslate">moment#startOf</code> are supported for <code class="notranslate">moment#isAfter</code>.</p>
<pre class="notranslate"><code>year month week isoWeek day hour minute second
</code></pre>
<p>If nothing is passed to <code class="notranslate">moment#isAfter</code>, it will default to the current time.</p>
<pre class="notranslate"><code class="language-javascript">moment().isAfter(); // false
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/is-same-or-before/" name="/query/is-same-or-before/"></a>
<h3 class="docs-method-title" id="Is-Same-or-Before-2.11.0+"> <a href="#/query/is-same-or-before/">Is Same or Before</a> <span>2.11.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/05-query/04-is-same-or-before.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isSameOrBefore(Moment|String|Number|Date|Array);
moment().isSameOrBefore(Moment|String|Number|Date|Array, String);
</code></pre>
</div>
<p>Check if a moment is before or the same as another moment. The first argument will be parsed as a moment, if not already so.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isSameOrBefore('2010-10-21');  // true
moment('2010-10-20').isSameOrBefore('2010-10-20');  // true
moment('2010-10-20').isSameOrBefore('2010-10-19');  // false
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.</p>
<p>As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isSameOrBefore('2009-12-31', 'year'); // false
moment('2010-10-20').isSameOrBefore('2010-12-31', 'year'); // true
moment('2010-10-20').isSameOrBefore('2011-01-01', 'year'); // true
</code></pre>
<p>Like <code class="notranslate">moment#isAfter</code> and <code class="notranslate">moment#isSame</code>, any of the units of time that are supported for <code class="notranslate">moment#startOf</code> are supported for <code class="notranslate">moment#isSameOrBefore</code>:</p>
<pre class="notranslate"><code>year month week isoWeek day hour minute second
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/is-same-or-after/" name="/query/is-same-or-after/"></a>
<h3 class="docs-method-title" id="Is-Same-or-After-2.11.0+"> <a href="#/query/is-same-or-after/">Is Same or After</a> <span>2.11.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/05-query/05-is-same-or-after.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isSameOrAfter(Moment|String|Number|Date|Array);
moment().isSameOrAfter(Moment|String|Number|Date|Array, String);
</code></pre>
</div>
<p>Check if a moment is after or the same as another moment. The first argument will be parsed as a moment, if not already so.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isSameOrAfter('2010-10-19'); // true
moment('2010-10-20').isSameOrAfter('2010-10-20'); // true
moment('2010-10-20').isSameOrAfter('2010-10-21'); // false
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass the units as the second parameter.</p>
<p>As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isSameOrAfter('2011-12-31', 'year'); // false
moment('2010-10-20').isSameOrAfter('2010-01-01', 'year'); // true
moment('2010-10-20').isSameOrAfter('2009-12-31', 'year'); // true
</code></pre>
<p>Like <code class="notranslate">moment#isSame</code> and <code class="notranslate">moment#isBefore</code>, any of the units of time that are supported for <code class="notranslate">moment#startOf</code> are supported for <code class="notranslate">moment#isSameOrAfter</code>:</p>
<pre class="notranslate"><code>year month week isoWeek day hour minute second
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/is-between/" name="/query/is-between/"></a>
<h3 class="docs-method-title" id="Is-Between-2.9.0+"> <a href="#/query/is-between/">Is Between</a> <span>2.9.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/05-query/06-is-between.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">//From 2.13.0 onward
moment().isBetween(moment-like, moment-like);
moment().isBetween(moment-like, moment-like, String);
moment().isBetween(moment-like, moment-like, String, String);
// where moment-like is Moment|String|Number|Date|Array

//2.9.0 to 2.12.0
moment().isBetween(moment-like, moment-like);
moment().isBetween(moment-like, moment-like, String);
// where moment-like is Moment|String|Number|Date|Array
</code></pre>
</div>
<p>Check if a moment is between two other moments, optionally looking at unit scale (minutes, hours, days, etc). The match is exclusive. The first two arguments will be parsed as moments, if not already so.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isBetween('2010-10-19', '2010-10-25'); // true
moment('2010-10-20').isBetween('2010-10-19', undefined); // true, since moment(undefined) evaluates as moment()
</code></pre>
<p>Note that the order of the two arguments matter: the "smaller" date should be in the first argument.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isBetween('2010-10-19', '2010-10-25'); // true
moment('2010-10-20').isBetween('2010-10-25', '2010-10-19'); // false
</code></pre>
<p>If you want to limit the granularity to a unit other than milliseconds, pass the units as the third parameter.</p>
<pre class="notranslate"><code class="language-javascript">moment('2010-10-20').isBetween('2010-01-01', '2012-01-01', 'year'); // false
moment('2010-10-20').isBetween('2009-12-31', '2012-01-01', 'year'); // true
</code></pre>
<p>Like <code class="notranslate">moment#isSame</code>, <code class="notranslate">moment#isBefore</code>, <code class="notranslate">moment#isAfter</code> any of the units of time that are supported for <code class="notranslate">moment#startOf</code> are supported for <code class="notranslate">moment#isBetween</code>. Year, month, week, isoWeek, day, hour, minute, and second.</p>
<p>Version <strong>2.13.0</strong> introduces inclusivity. A <code class="notranslate">[</code> indicates inclusion of a value. A <code class="notranslate">(</code> indicates exclusion. If the inclusivity parameter is used, both indicators must be passed.</p>
<pre class="notranslate"><code class="language-javascript">moment('2016-10-30').isBetween('2016-10-30', '2016-12-30', undefined, '()'); //false
moment('2016-10-30').isBetween('2016-10-30', '2016-12-30', undefined, '[)'); //true
moment('2016-10-30').isBetween('2016-01-01', '2016-10-30', undefined, '()'); //false
moment('2016-10-30').isBetween('2016-01-01', '2016-10-30', undefined, '(]'); //true
moment('2016-10-30').isBetween('2016-10-30', '2016-10-30', undefined, '[]'); //true
</code></pre>
<p>Note that in the event that the <code class="notranslate">from</code> and <code class="notranslate">to</code> parameters are the same, but the inclusivity parameters are different, false will preside.</p>
<pre class="notranslate"><code class="language-javascript">moment('2016-10-30').isBetween('2016-10-30', '2016-10-30', undefined, '(]'); //false
</code></pre>
<p>If the inclusivity parameter is not specified, Moment will default to <code class="notranslate">()</code>.</p>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/is-daylight-saving-time/" name="/query/is-daylight-saving-time/"></a>
<h3 class="docs-method-title" id="Is-Daylight-Saving-Time-1.2.0+"> <a href="#/query/is-daylight-saving-time/">Is Daylight Saving Time</a> <span>1.2.0+</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/05-query/07-is-daylight-saving-time.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment().isDST();
</code></pre>
</div>
<p><code class="notranslate">moment#isDST</code> checks if the current moment is in daylight saving time.</p>
<pre class="notranslate"><code class="language-javascript">moment([2011, 2, 12]).isDST(); // false, March 12 2011 is not DST
moment([2011, 2, 14]).isDST(); // true, March 14 2011 is DST
// This example is for "en" locale: https://www.timeanddate.com/time/dst/2011.html
</code></pre>
</div>
</article>
<article class="docs-method">
<a class="docs-method-target" id="/query/is-dst-shifted/" name="/query/is-dst-shifted/"></a>
<h3 class="docs-method-title" id="Is-DST-Shifted-From-2.3.0,-Deprecated-2.14.0"> <a href="#/query/is-dst-shifted/">Is DST Shifted</a> <span>From 2.3.0, Deprecated 2.14.0</span> </h3>
<a class="docs-method-edit" href="javascript:window.open('https://github.com/moment/momentjs.com/blob/master/docs/moment/05-query/08-is-dst-shifted.md');" target="_blank" rel="noopener noreferrer">edit <i class="fa fa-external-link"></i></a>
<div class="docs-method-prose">
<div class="docs-method-signature">
<pre class="notranslate"><code class="language-js">moment('2013-03-10 2:30', 'YYYY-MM-DD HH:mm').isDSTShifted()
</code></pre>
</div>
<p><strong>Note:</strong> As of version <strong>2.14.0</strong> thi</p>
</div>
</article></div>
</div>
 </section>
<div class="right-sidebar">
<div class="affix"><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6108808167664152" data-ad-slot="3102929424" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
</div>
</div>
<div class="ft">
<a href="#toolbar-title" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a>
<footer class="footer">
<div class="footer__container--normal">
<img alt="扫码关注公众号" title="扫码关注公众号" src="static/picture/qr-code.png" width="170" height="170">
<div class="footer__description--normal">
<p class="paragraph footer__author--normal">Docs4dev<sup class="super">&#xAE;</sup>
</p>
<p class="paragraph footer__quote&#45;&#45;normal">
如果你在使用过程中遇到任何问题，可以在 <a href="javascript:window.open('https://github.com/docs4dev/docs4dev-issues');" target="_blank" rel="noopener noreferrer">这里<i class="fa fa-external-link"></i></a> 提issue。
</p>
<div class="footer__main--normal">
<p class="paragraph footer__main__paragraph--normal copyright" style="color: #666 !important;">
<a href="javascript:window.open('https://beian.miit.gov.cn/');">
蜀ICP备14021783号-6
</a>
</p>
<p class="paragraph footer__main__paragraph--normal copyright" style="color: #666 !important;">
Copyright &#xA9; Docs4dev all
right reserved, powered by <a href="index2.html" target="_blank">Docs4dev</a></p>
</div>
</div>
</div>
<div class="box__issues">
</div>
</footer>
</div>
</div>
</div>
</div>
</div>
<script>
  var hasToc = true;
  /*  var downloadable = /!*false*!/ false;
    var editable = /!*false*!/ false;
    var code = /!*"momentjs"*!/ false;
    var version = /!*"2.24.0"*!/ false;
    var type = /!*"documentation"*!/ false;
    var lang = /!*"en"*!/ 'en';
    //edit link
    require(["gitbook", "jQuery"], function (gitbook, $) {
      gitbook.events.bind('start', function (e, config) {
        // Add edit toolbar to left
        var chapterId = /!*24798*!/ 0;
        if (downloadable) {
          gitbook.toolbar.createButton({
            icon: 'fa fa-download',
            text: '下载',
            onClick: function () {
              window.open('/download?code=' + code + '&version=' + version + '&type=' + type + '&lang=' + lang);
            }
          });
        }
        if (editable) {
          gitbook.toolbar.createButton({
            icon: 'fa fa-edit',
            text: '编辑此页',
            onClick: function () {
              window.open('/docs/edit?chapterId=' + chapterId + '&lang=' + lang);
            }
          });
        }
      });
    });*/
</script>
<script>
    var code = "momentjs";
    var lang = "en";
  </script>

<script src="static/js/autocomplete-js.js"></script>
<script src="static/js/app.min.js"></script>
<script src="static/js/search.min.js"></script>
</body>
</html>
